ios 给label添加横线
来源:互联网 发布:部落冲突九本满防数据 编辑:程序博客网 时间:2024/04/30 11:59
UILabel *labelTitle = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-100, 130, 200, 30)];
// labelTitle.text = @"星座运势";
labelTitle.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:labelTitle];
//给label添加横线
NSString *stratt = @"星座运势解析";
NSMutableAttributedString *attri = [[NSMutableAttributedString alloc]initWithString:stratt];
[attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid|NSUnderlineStyleSingle) range:NSMakeRange(0, stratt.length)];
[attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(0, stratt.length)];
[labelTitle setAttributedText:attri];
@implementation UILabel (colorLab)
// 设置某段字的颜色
- (void)setColor:(UIColor *)color fromIndex:(NSInteger)location length:(NSInteger)length
{
NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:self.text];
[str addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(location, length)];
self.attributedText = str;
}
// 设置某段字的字体
- (void)setFont:(UIFont *)font fromIndex:(NSInteger)location length:(NSInteger)length
{
NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:self.text];
[str addAttribute:NSFontAttributeName value:font range:NSMakeRange(location, length)];
self.attributedText = str;
}
//设置行间距
-(void)setText:(NSString *)text withLineSpacing:(float)spacing
{
NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:text];
NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle1 setLineSpacing:spacing];
[attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [text length])];
[self setAttributedText:attributedString1];
//[self sizeToFit];
}
//添加下划线
-(void)setUnderLineWithColor:(UIColor*)color
{
NSMutableAttributedString *attri = [[NSMutableAttributedString alloc]initWithString:self.text];
[attri addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, self.text.length)];
if (color)
{
[attri addAttribute:NSUnderlineColorAttributeName value:color range:NSMakeRange(0, self.text.length)];
}
[self setAttributedText:attri];
}
//添加中划线
-(void)setMidLineWithColor:(UIColor*)color
{
NSMutableAttributedString *attri = [[NSMutableAttributedString alloc]initWithString:self.text];
[attri addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, self.text.length)];
if (color)
{
[attri addAttribute:NSStrikethroughColorAttributeName value:color range:NSMakeRange(0, self.text.length)];
}
[self setAttributedText:attri];
}
@end
// labelTitle.text = @"星座运势";
labelTitle.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:labelTitle];
//给label添加横线
NSString *stratt = @"星座运势解析";
NSMutableAttributedString *attri = [[NSMutableAttributedString alloc]initWithString:stratt];
[attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid|NSUnderlineStyleSingle) range:NSMakeRange(0, stratt.length)];
[attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(0, stratt.length)];
[labelTitle setAttributedText:attri];
@implementation UILabel (colorLab)
// 设置某段字的颜色
- (void)setColor:(UIColor *)color fromIndex:(NSInteger)location length:(NSInteger)length
{
NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:self.text];
[str addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(location, length)];
self.attributedText = str;
}
// 设置某段字的字体
- (void)setFont:(UIFont *)font fromIndex:(NSInteger)location length:(NSInteger)length
{
NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:self.text];
[str addAttribute:NSFontAttributeName value:font range:NSMakeRange(location, length)];
self.attributedText = str;
}
//设置行间距
-(void)setText:(NSString *)text withLineSpacing:(float)spacing
{
NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:text];
NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle1 setLineSpacing:spacing];
[attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [text length])];
[self setAttributedText:attributedString1];
//[self sizeToFit];
}
//添加下划线
-(void)setUnderLineWithColor:(UIColor*)color
{
NSMutableAttributedString *attri = [[NSMutableAttributedString alloc]initWithString:self.text];
[attri addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, self.text.length)];
if (color)
{
[attri addAttribute:NSUnderlineColorAttributeName value:color range:NSMakeRange(0, self.text.length)];
}
[self setAttributedText:attri];
}
//添加中划线
-(void)setMidLineWithColor:(UIColor*)color
{
NSMutableAttributedString *attri = [[NSMutableAttributedString alloc]initWithString:self.text];
[attri addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, self.text.length)];
if (color)
{
[attri addAttribute:NSStrikethroughColorAttributeName value:color range:NSMakeRange(0, self.text.length)];
}
[self setAttributedText:attri];
}
@end
0 0
- ios 给label添加横线
- iOS给label添加下划线
- iOS label 加下横线
- iOS 给label添加点击事件
- iOS 给 label 添加点击事件
- iOS 给NSString文字上添加横线 中间和下划线
- iOS 给NSString文字中间或底部添加横线
- 给TextView底部添加横线
- FPDFK中给文字添加横线
- 给label添加点击事件
- 给label添加删除线
- 给label添加点击方法
- iOS 给文字上面加贯穿横线
- iOS 在UILabel上添加横线
- iOS 富文本添加价格 横线
- label画横线
- iOS Label添加删除线
- iOS Label添加删除线
- H.264码流结构
- EQueue - 一个C#写的开源分布式消息队列的总体介绍
- 21.View,Label,Button,TextField
- windows下解决快捷键失效的万能方法
- hdu3768Shopping 最短路+暴力
- ios 给label添加横线
- Elasticsearch+Logstash+Kibana配置
- POJ 2452 (RMQ + 二分)
- EQueue - 详细谈一下消息持久化以及消息堆积的设计
- UE4与WEB服务器交互(json)
- android 占位符使用
- Android 5.0(L) 的MediaSession架构分析(转载)
- 客户端和服务器通讯 方法(2)
- NSSet 集合