【问题标题】:UITableViewCell with add photo button like in Contacts app?UITableViewCell 与联系人应用程序中的添加照片按钮?
【发布时间】:2011-10-26 00:15:24
【问题描述】:

如何像在联系人应用程序中一样创建带有添加照片按钮的 UITableViewCell?

UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(20, 1, 70, 40)] autorelease];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:16];

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(70, 10, 217, 30)];
textField.backgroundColor = [UIColor clearColor];
textField.returnKeyType = UIReturnKeyDone;

[cell.contentView addSubview:label];
[cell.contentView addSubview:textField];

【问题讨论】:

    标签: iphone objective-c xcode cocoa-touch ipad


    【解决方案1】:

    将照片添加到 tableviewcell 并不太复杂。

    UIButton* btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btn setFrame:CGRectMake(5,0,40,30)];
    
    [btn setBackGoundImage:[UIImage imageName:@"ABC.png"]];
    
    [cell.contentView addSubview:btn];
    

    如果您希望您的应用程序看起来像 Iphone 中的联系人应用程序,那么您需要使用滚动视图而不是表格视图。

    【讨论】:

      【解决方案2】:

      只需添加一个 UIButton 并将缩略图设置为其 backgroundimage 或 imageview 属性。

      【讨论】:

        【解决方案3】:

        最简单的方法是使用 xib 制作 UITableViewCell 的自定义子类。然后你只需要像这样在-tableView:cellForRowAtIndexPath 方法中选择你的单元格

        myCustomCell *cell = (myCustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        然后配置它们

        【讨论】:

        • 我已经这样做了: UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(20, 1, 70, 40)] autorelease]; label.backgroundColor = [UIColor clearColor]; label.font = [UIFont boldSystemFontOfSize:16]; UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(70, 10, 217, 30)]; textField.backgroundColor = [UIColor clearColor]; textField.returnKeyType = UIReturnKeyDone; [cell.contentView addSubview:label]; [cell.contentView addSubview:textField];
        • 我想知道如何添加这样的 UIButton
        • 你必须做同样的事情,在你的代码中添加一个 UIButton 并使用[button addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];,然后你必须实现-buttonPressed
        • 你看到照片了吗 i.stack.imgur.com/nrOt8.png 我希望按钮在 UITableViewCell 之外
        • 可以,但是没有tableViewCell,也没有tableView。在我看来,这只是一个常见的 UIView。但是如果你想添加子视图(uibutton 是一个 uiview)你仍然可以这样做
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-11-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-06
        • 1970-01-01
        相关资源
        最近更新 更多