ios - 圆角矩形框绘制-iOS

标签 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

最佳答案

您提供的示例可能是作为 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 )

关于ios - 圆角矩形框绘制-iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12644163/

相关文章:

ios - Cognito getIdentityId() 对未经身份验证的用户无法快速工作

ios - 如何在用户放大 UIScrollView 时隐藏某些内容,然后在他们缩小时显示它?

ios - UITextfield的语义问题

ios - UIAlertController 或 UITextField 中的 UILabel 类似 UILabel

ios - 使用 CLI 命令或 Ionic 配置将 AdSupport Framework 添加到 Xcode 项目

ios - 如何获取结构中的数据

ios - 在 UITableViewCell 内动画 UILabel 文本更改

ios - UISlider 不更新 Swift 中的当前值

ios - 它们如何使文本框彼此粘在一起?

ios - 旧的 swift 代码不起作用(动画 UIView)