iOS
来源:互联网 发布:刻绘大师端口怎么设置 编辑:程序博客网 时间:2024/06/05 20:29
NSArray *Arr = @[@"123456",@"123456789",@"qwertyuiop",@"asdfghjkl",@"zxcvbnm",@"abcdefg",@"aaaa",@"bbbb",@"cccc",@"f",@"fretretq",@"fewrtewt",@"a beautiful day",@"够了没有呢",@"哎 还是多写几个吧",@"丰富特权",@"123456",@"123456789",@"qwertyuiop",@"asdfghjkl",@"zxcvbnm",@"abcdefg",@"aaaa",@"bbbb",@"cccc",@"f",@"fretretq",@"fewrtewt",@"a beautiful day",@"够了没有呢",@"哎 还是多写几个吧",@"丰富特权"];
//创建各个Button
NSInteger currentRight = 0; // 记录当前Btn的right(右边)
NSInteger currentBotton = 0; // 记录当前btn的bottom(底部)
for (int i =0; i < Arr.count; i++)
{
UIButton *Btn=[UIButtonbuttonWithType:UIButtonTypeCustom];
Btn.frame =CGRectMake(currentRight +15, currentBotton +30, 80, 25);
// 计算字体长度
CGSize size = [Arr[i] boundingRectWithSize:CGSizeMake(200,30000)options:NSStringDrawingUsesLineFragmentOriginattributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:13]}context:nil].size;
// 更新btn的右边
currentRight = currentRight + size.width +40;
// 判断是否换行
if (i < Arr.count -1)
{
NSString *str = Arr[i + 1];
// 计算字体长度
CGSize size = [str boundingRectWithSize:CGSizeMake(200,30000)options:NSStringDrawingUsesLineFragmentOriginattributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:13]}context:nil].size;
if (currentRight + size.width >SCREEN_WIDTH -60)
{
currentRight = 0;
currentBotton = currentBotton + 45;
}
}
// 更新每个Btn的frame
CGRect frame = CGRectMake(Btn.frame.origin.x, Btn.frame.origin.y, size.width +30, size.height +20);
Btn.frame = frame;
// 设置btn的属性
Btn.titleLabel.font=[UIFontsystemFontOfSize:13];
Btn.backgroundColor=[UIColorclearColor];
[Btn setTitleColor:[UIColorcolorWithRed:69/255.0green:69/255.0blue:68/255.0alpha:1.0]forState:UIControlStateNormal];
[Btn setTitle:Arr[i]forState:UIControlStateNormal];
Btn.titleLabel.adjustsFontSizeToFitWidth = YES;
Btn.layer.cornerRadius=5;
Btn.layer.borderColor=[UIColorlightGrayColor].CGColor;
Btn.layer.borderWidth=0.7;
Btn.layer.masksToBounds=YES;
[self.viewaddSubview:Btn];
}
- iOS
- iOS
- IOS
- iOS
- iOS
- IOS
- ios
- iOS
- iOS
- IOS
- iOS
- ios
- ios ~~~~~
- ios
- IOS
- IOS
- IOS
- ios
- iOS- 上传代码到Github
- spring boot 获取指定类中自定义注解的内容
- 省级期刊发表流程
- 导出数据库表的结构与数据
- Android版 RTSP客户端
- iOS
- Hibernate增删改查
- oracle 查询锁表语句
- 基于阿里的Node全栈之路(四)前后端分离进阶-自动上传前端代码到OSS
- 山东省教师教育网-学习课程
- 构建高性能数据库缓存之redis主从复制
- poj3107 Godfather(鬼题畜译)
- C#生成PDF总结
- 下面代码执行的结果是多少?