ios 按钮下面加下划线_IOS UIlabel 、UIButton添加下划线
1.给UILabel 添加下划线
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, 300, 100)];
label.backgroundColor = [UIColor redColor];
label.numberOfLines = 3;
NSMutableAttributedString *content = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"您的待办业务条fasdfasdfosadfjasdkljfklasjklfjasdlkjfklasdjklfjalskdjflkadsj"]];
NSRange contentRange = {0,[content length]};
[content addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:contentRange];
label.attributedText = content;
[self.view addSubview:label];
2.http://blog.csdn.net/chaoyuan899/article/details/38306141
方法一:
NSMutableAttributedString *str = [[NSMutableAttributedStringalloc]initWithString:@"查看所有中奖记录"];
NSRange strRange = {0,[strlength]};
[straddAttribute:NSUnderlineStyleAttributeNamevalue:[NSNumbernumberWithInteger:NSUnderlineStyleSingle]range:strRange];
[_awardDisplayBtnsetAttributedTitle:strforState:UIControlStateNormal];
方法二:
HyperlinksButton.h
#import
@interface HyperlinksButton : UIButton
{
UIColor *lineColor;
}
-(void)setColor:(UIColor*)color;
@end
HyperlinksButton.m
#import "HyperlinksButton.h"
@implementation HyperlinksButton
- (id)initWithFrame:(CGRect)frame
{
self = [superinitWithFrame:frame];
if (self) {
}
return self;
}
-(void)setColor:(UIColor *)color{
lineColor = [colorcopy];
[selfsetNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
CGRect textRect = self.titleLabel.frame;
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGFloat descender = self.titleLabel.font.descender;
if([lineColorisKindOfClass:[UIColorclass]]){
CGContextSetStrokeColorWithColor(contextRef, lineColor.CGColor);
}
CGContextMoveToPoint(contextRef, textRect.origin.x, textRect.origin.y + textRect.size.height + descender+1);
CGContextAddLineToPoint(contextRef, textRect.origin.x + textRect.size.width, textRect.origin.y + textRect.size.height + descender+1);
CGContextClosePath(contextRef);
CGContextDrawPath(contextRef, kCGPathStroke);
}
@end
直接将这个类 copy 到工程中,,然后将需要加下划线的 Button 类名改为 HyperlinksButton就可以了,提供了 setColor: 这个接口,可以设置下划线颜色,代码很简单,不解释了。UILabel 同理可得。
示例结果:
代码在这里。
来源:https://www.cnblogs.com/someonelikeyou/p/4011547.html
ios 按钮下面加下划线_IOS UIlabel 、UIButton添加下划线相关推荐
- ios 按钮下面加下划线_iOS开发UILabel和UIButton添加下划线
关于UILabel和UIButton有的时候需要添加下划线,一般有两种方式通过默认的NSMutableAttributedString设置,第二种就是在drawRect中画一条下划线,本文就简单的选择 ...
- ios 按钮下面加下划线_如何在iOS按钮上的文字添加下划线
在开发ios的时候很多用户们都会想如何在iOS按钮上的文字添加下划线,那么接下来的内容中我们就一起去看看在iOS按钮上的文字添加下划线的方法. 问题:实现下图中右侧的按钮文字效果 方法: [MyToo ...
- div html 下边加横线_CSS如何给文字添加下划线样式?
在CSS中可以使用text-decoration属性或border-bottom属性来给文字添加下划线样式.下面本篇文章就来给大家介绍一下,希望对大家有所帮助. 方法1:使用text-decorati ...
- html5添加下划线虚线,web中添加下划线的方法及优缺点
有很多种添加下划线样式的方法.可能你还记得<Crafting link underlines on Medium>这篇文章.Medium 并没有尝试特殊的方法,只是想创建一个漂亮的看起来正 ...
- linux中文本怎么添加下划线,Android实现EditText添加下划线
在安卓高版本,默认是有下划线的,其默认下划线的颜色是由其主题颜色来控制的! 控制如下: @color/colorPrimary @color/colorPrimaryDark **@color/col ...
- ios 从assets加载图片_iOS 图片加载和处理
一.图片显示 图片的显示分为三步:加载.解码.渲染.解码和渲染是由 UIKit 进行,通常我们操作的只有加载. 以 UIImageView 为例.当其显示在屏幕上时,需要 UIImage 作为数据源. ...
- ios 从assets加载图片_iOS 使用Assets.xcassets添加启动图和Icon
需要的尺寸 640 * 960 750 * 1334 640 * 1136 1242 * 2208 1. 首先我们要将 info.plist 文件中的 Launch screen interface ...
- html显示下滑线,html超链接添加下划线
UILabel *linkLabel = [[UILabel alloc]init]; linkLabel.frame = CG... 方法一: 在 和加 ...
- 在Word 2007中为字符添加上划线
在Word中为字符添加下划线是一件很容易的事情,但是要添加上划线就是不那么方便了.偏偏在某些时候我们还真就需要为指定的字符添加上划线,比如在数学文档中要输入平均数的数学符号,就是在指定变量上加一个短线 ...
最新文章
- 用Handler的post()方法来传递线程中的代码段到主线程中执行
- Swift基础之闭包
- mysql java 分页实体类_Java GUI+mysql+分页查询
- LUA 利用#遍历表的问题
- 棘手的问题input:当在严格模式中使用 Vuex 时,在属于 Vuex 的 state 上使用 v-model,input
- oracle建表时添加comment,MYSQL中创建表时可以直接声明comment,ORACLE中似乎不可以,那么oracle该怎样简明地声明comment...
- 16.2 调色板动画
- 技能梳理27@体感机械臂
- aac和mp3在码率压缩的一些事
- 【SEAN的日志】如何突破微信小程序2M限制?
- 被王思聪抽奖炸了的微博,究竟是算法背锅还是自己作死?
- 高刷新率电视机有必要吗?
- 百色职称计算机,百色报考职称高级
- 如何查看CDR文件是出自哪个版本?
- MacOS清理DNS缓存的终端代码推荐
- Android开发中遇到的坑
- vscode上的git三部曲+git pull操作
- python专场——暴力破解(DVWA)
- python将图片拼接为视频
- XSL中特殊符号详解
热门文章
- Fetch的使用及兼容ie的处理
- Python入门基础(6)--面向对象/类和对象/魔术方法
- 语音识别ASR - HTK(HResults)计算字错率WER、句错率SER
- GP 查询sql进程,kill进程
- git push失败,报错fatal: does not appear to a git repository Could not read from remote repository
- 英读廊——艺术家、穷人和音乐家之10美元的奇异之旅(The Artist, the Poor Man, and the Musician)
- Oracle索引、视图、序列、同义词、事务、锁机制详解
- nginx 如何使用rewrite
- ET钱包2月25日早报 | 过去24小时EOS区块链活跃度指数蝉联榜首
- 寒假训练八(优先队列)2020.02.14(7题)