iOS-UIKit(UILabel.h常用技巧1(随字体多行后的高度,渐变字体Label,自适应高度,添加边框))
2015-10-28 11:28
441 查看
1、计算UIlabel随字体多行后的高度
CGRect bounds = CGRectMake(0,
0, 200, 300);
CGRect heightLabel = [myLabel textRectForBounds:bounds
limitedToNumberOfLines:20];
//计算20行后的Label的Frame
NSLog(@"%f",heightLabel.size.height);
2、UILabel根据字数多少自动实现适应高度
UILabel *msgLabel = [[UILabel alloc]
initWithFrame:CGRectMake(15,
45, 0, 0)];
msgLabel.backgroundColor = [UIColor lightTextColor];
[msgLabel setNumberOfLines:0];
msgLabel.lineBreakMode = UILineBreakModeWordWrap;
msgLabel.font = [UIFont fontWithName:@"Arial" size:12];
CGSize size = CGSizeMake(290,1000);
msgLabel.text = @"获取到的deviceToken,我们可以通过webservice服务提
交给.net应用程序,这里我简单处理,直接打印出来,拷贝到.net应用环境中使
用。";
CGSize msgSie = [msgLabel.text sizeWithFont:fonts
constrainedToSize:size];
[msgLabel setFrame:CGRectMake(15,
45, 290, msgSie.height)];
3、渐变字体Label
UIColor *titleColor = [UIColor colorWithPatternImage:[UIImage
imageNamed:@"btn.png"]];
NSString *title =
@"Setting";
UILabel *titleLabel = [[UILabelalloc]
initWithFrame:CGRectMake(0,0,
80,44)];
titleLabel.textColor = titleColor;
titleLabel.text = title;
titleLabel.font = [UIFont boldSystemFontOfSize:20];
titleLabel.backgroundColor = [UIColor clearColor];
[self.view addSubview:titleLabel];
[titleLabel release];
4、Label添加边框
titleLabel.layer.borderColor = [[UIColor grayColor] CGColor];
titleLabel.layer.borderWidth = 2;
CGRect bounds = CGRectMake(0,
0, 200, 300);
CGRect heightLabel = [myLabel textRectForBounds:bounds
limitedToNumberOfLines:20];
//计算20行后的Label的Frame
NSLog(@"%f",heightLabel.size.height);
2、UILabel根据字数多少自动实现适应高度
UILabel *msgLabel = [[UILabel alloc]
initWithFrame:CGRectMake(15,
45, 0, 0)];
msgLabel.backgroundColor = [UIColor lightTextColor];
[msgLabel setNumberOfLines:0];
msgLabel.lineBreakMode = UILineBreakModeWordWrap;
msgLabel.font = [UIFont fontWithName:@"Arial" size:12];
CGSize size = CGSizeMake(290,1000);
msgLabel.text = @"获取到的deviceToken,我们可以通过webservice服务提
交给.net应用程序,这里我简单处理,直接打印出来,拷贝到.net应用环境中使
用。";
CGSize msgSie = [msgLabel.text sizeWithFont:fonts
constrainedToSize:size];
[msgLabel setFrame:CGRectMake(15,
45, 290, msgSie.height)];
3、渐变字体Label
UIColor *titleColor = [UIColor colorWithPatternImage:[UIImage
imageNamed:@"btn.png"]];
NSString *title =
@"Setting";
UILabel *titleLabel = [[UILabelalloc]
initWithFrame:CGRectMake(0,0,
80,44)];
titleLabel.textColor = titleColor;
titleLabel.text = title;
titleLabel.font = [UIFont boldSystemFontOfSize:20];
titleLabel.backgroundColor = [UIColor clearColor];
[self.view addSubview:titleLabel];
[titleLabel release];
4、Label添加边框
titleLabel.layer.borderColor = [[UIColor grayColor] CGColor];
titleLabel.layer.borderWidth = 2;
相关文章推荐
- UISwitch 圆点按钮
- create sequence
- IOS-21-UI懒加载概念及原理
- iOS中 UIView 的 hitTest 使用
- select, iocp, epoll,kqueue及各种I/O复用机制
- UI 常用方法总结之--- UITableView
- CE3和UE3在多线程渲染方面的简单对比
- SqlCommandBuilder类批量更新excel或者CSV数据的方法
- Uip在STM32平台移植
- NGUI 3.5教程(八)Scroll Bar 滚动条-制作聊天框
- ios GPUImageGaussianBlurFilter 苹果模糊效果
- 如何获取SharePoint 2013 Build Numbers?
- UIscrollView滚动时调用的方法
- iOS开发之不会就百度: UISearchController 修改外观
- UIProgressView进度条
- UIView在Xib中的边框设置
- 如何避免FragmentTabHost切换Fragment时重复加载UI
- Building an MFC project for a non-Unicode character set is deprecated
- UINavigationViewController显示新页面后,隐藏下面的TabBar
- priority_queue,以及运算符重载