自动适配标签显示
来源:互联网 发布:c 游戏编程入门教程 编辑:程序博客网 时间:2024/05/21 14:52
@interface ViewController ()
{
NSArray *arr;
CGFloat height;
}
@end
@implementation ViewController
(void)viewDidLoad {
[super viewDidLoad];
self.title = @”多标签”;
self.view.backgroundColor = [UIColor whiteColor];arr = @[@”福利”,@”责任心”,@”呵呵呵呵呵呵”,@”秘密”,@”帅”,@”小小”,@”福利”,@”责任心”,@”呵呵呵呵呵呵”,@”秘密”,@”帅”,@”小小”,@”帅”,@”帅”];
[self setLableView];
}(void)setLableView
{
CGFloat x = 10.0f;
CGFloat y = 74.0f;
height = 40;
CGFloat surplusWidth = self.view.frame.size.width-20; //剩余宽度
CGFloat lableWidth = 0; //标签的宽度for (NSString *string in arr) {
CGSize size = [string sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize: CGSizeMake(MAXFLOAT,30) lineBreakMode:NSLineBreakByWordWrapping];lableWidth = size.width+10;if (surplusWidth < lableWidth) { y = y+40; x = 10; surplusWidth = self.view.frame.size.width-20; height = height +40;}UIButton *lableBtn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, lableWidth, 30)];[lableBtn setTitle:string forState:UIControlStateNormal];[lableBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];lableBtn.backgroundColor = [UIColor blueColor];lableBtn.layer.cornerRadius = 5;lableBtn.layer.masksToBounds = YES;lableBtn.titleLabel.font = [UIFont systemFontOfSize:13];[self.view addSubview:lableBtn];x = lableWidth+10 + x;surplusWidth = surplusWidth - lableWidth -10;NSLog(@"%f",height);
}
}
@end
0 0
- 自动适配标签显示
- 根据传入值,自动显示标签 select 下拉选项
- 如何在JSP页面显示标签时自动带出标签类型表中的类型名称字段
- jsp中 根据传入值,采用javascript自动显示标签下拉选项
- JS根据表单中的选项,自动生成span标签后显示选中的内容
- Android自定义控件实现标签的显示自动换行(一)
- Android开发之实现图片自动滚动显示标签的ViewPager
- source insight配置(自动排版,多标签显示,注释,删除中文乱码)
- div+pre标签的组合实现文本原格式显示与自动换行
- firefox-5.x关于img标签的load事件、svg、ff5.4audio标签显示的适配tip
- pre标签自动换行
- 标签自动补全
- struts2 标签自动提示
- 标签自动排列 笔记
- struts2标签自动提示
- 网页自动刷新标签
- html标签自动刷新
- FlowLayout 自动换行标签
- mysql中varchar(10)中定义的长度到底是字符长度还是字节长度
- 【Qt开发】QT中显示图像数据
- 1010. Radix (25)
- php调用sphinx
- java 集合1--接口及父类介绍
- 自动适配标签显示
- tomcat运行springmvc项目:m2e-wtp error: <path>/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF (No such
- java基础学习总结——关于Java中的paint,repaint,update三个方法的关系
- 安卓谷歌电子市场学习笔记系列——BaseProtocol
- [Sencha Test] 4、测试已有应用程序
- http://bailian.openjudge.cn/practice/2816/2816:红与黑
- PE程序壳编写学习过程(一)PE文件的读取
- *数学--规律-技巧
- 汇编指令CLI/STI