2012-09-28 154 views
1

如何创建如图所示的圆角矩形?另外我的第二个问题是如何获得多行,如何格式化成多行,如红色矩形所示?提前致谢!。圆角矩形框绘制-iOS

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

你提供大概为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