国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

IOS 開發之UILabel 或者 UIButton加下劃線鏈接

2019-10-21 18:45:28
字體:
來源:轉載
供稿:網友

IOS 開發之UILabel 或者 UIButton加下劃線鏈接

         本文主要介紹了IOS中 UILable及UIButton的帶下劃線鏈接的實現方法及附有源碼下載,大家開發IOS 應用有需要的可以參考下:

方法一:

NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"查看所有中獎記錄"]; NSRange strRange = {0,[str length]}; [str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:strRange]; [_awardDisplayBtn setAttributedTitle:str forState:UIControlStateNormal]; 

方法二:

HyperlinksButton.h

#import <UIKit/UIKit.h>  @interface HyperlinksButton : UIButton {   UIColor *lineColor; } -(void)setColor:(UIColor*)color; @end HyperlinksButton.m [objc] view plain copy print?#import "HyperlinksButton.h"  @implementation HyperlinksButton  - (id)initWithFrame:(CGRect)frame {   self = [super initWithFrame:frame];   if (self) {        }   return self; }  -(void)setColor:(UIColor *)color{   lineColor = [color copy];   [self setNeedsDisplay]; }   - (void) drawRect:(CGRect)rect {   CGRect textRect = self.titleLabel.frame;   CGContextRef contextRef = UIGraphicsGetCurrentContext();      CGFloat descender = self.titleLabel.font.descender;   if([lineColor isKindOfClass:[UIColor class]]){     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 同理可得。

示例結果:

UILabel,或者,UIButton標題加下劃線,IOS,開發之下劃線鏈接

源碼下載地址:https://github.com/chaoyuan899/HyperlinksButton#how-to-use

 

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 邯郸市| 仪征市| 麟游县| 武鸣县| 健康| 龙山县| 卢湾区| 阳春市| 儋州市| 江陵县| 武汉市| 桐城市| 嘉祥县| 玉田县| 镇坪县| 桂林市| 高雄市| 保靖县| 大埔区| 邵武市| 乃东县| 绍兴市| 丘北县| 磴口县| 中牟县| 镇雄县| 永年县| 兴安盟| 阜平县| 虎林市| 泗阳县| 盱眙县| 成安县| 曲松县| 临朐县| 达拉特旗| 晋中市| 海丰县| 南郑县| 汪清县| 长泰县|