最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

IOS 開(kāi)發(fā)之UILabel 或者 UIButton加下劃線鏈接

 更新時(shí)間:2017年07月15日 09:22:21   投稿:lqh  
這篇文章主要介紹了IOS 開(kāi)發(fā)之UILabel 或者 UIButton加下劃線鏈接的相關(guān)資料,需要的朋友可以參考下

IOS 開(kāi)發(fā)之UILabel 或者 UIButton加下劃線鏈接

         本文主要介紹了IOS中 UILable及UIButton的帶下劃線鏈接的實(shí)現(xiàn)方法及附有源碼下載,大家開(kāi)發(fā)IOS 應(yīng)用有需要的可以參考下:

方法一:

NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"查看所有中獎(jiǎng)記錄"]; 
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 

直接將這個(gè)類(lèi) copy 到工程中,,然后將需要加下劃線的 Button 類(lèi)名改為 HyperlinksButton就可以了,提供了 setColor: 這個(gè)接口,可以設(shè)置下劃線顏色,代碼很簡(jiǎn)單,不解釋了。UILabel 同理可得。

示例結(jié)果:

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

本站源碼下載:http://xiazai.jb51.net/201707/yuanma/HyperlinksButton-master(jb51.net).rar

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

相關(guān)文章

最新評(píng)論

车致| 延庆县| 嵩明县| 全州县| 临西县| 舟曲县| 德化县| 班戈县| 昌都县| 栖霞市| 蛟河市| 崇礼县| 五台县| 车致| 漯河市| 邳州市| 迭部县| 衡阳县| 涿州市| 梁河县| 安平县| 安丘市| 汶川县| 新乐市| 炎陵县| 额敏县| 五河县| 化德县| 云龙县| 舟曲县| 东乡县| 云南省| 分宜县| 容城县| 东兰县| 井研县| 苍梧县| 胶南市| 台江县| 龙岩市| 望谟县|