圆角矩形框绘制-iOS

时间:2012-09-28 16:49:07

标签: ios uiview uilabel cgrect

如何创建这个圆角矩形,如图所示?另外我的第二个问题是如何获得多行,如何格式化使其成为多条线,如红色矩形所示?提前谢谢!。

CGRect viewRect=CGRectMake(30,30,320,55);
UIView *myView=[[UIView alloc]initWithFrame:viewRect];
myView.backGroundColor=[UIColor whiteColor];
[self.view addSubview:myView]

UILabel *label=[[UILabel alloc]initwithFrame:CGRectMake(30,32,25,12)];
label.font=[UIFont fontWithName:"System" size:12];
label.textColor=[UIColor blackColor];
[self.view addSubview:label]

enter image description here

1 个答案:

答案 0 :(得分:1)

您提供的示例可能是UITableView。地址单元格采用UITableViewCellStyleValue2样式,左侧为textLabel(“地址”),右侧为detailTextLabel

以下是格式化单元格的方法:

static NSString *CellIdentifier = @"MyCell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"address";
cell.detailTextLabel.text = @"7200—7232 W Orem Dr\nHouston Texas 77085\nUnited States";
cell.detailTextLabel.numberOfLines = 3;
cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;

您还必须相应地调整单元格的高度,因为它会高于默认值。

来源: Multi-line UITableViewCell using UILabel(通过a similar Stack Overflow question

相关问题