一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專(zhuān)注于服務(wù)器技術(shù)及軟件下載分享
分類(lèi)導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

服務(wù)器之家 - 編程語(yǔ)言 - IOS - IOS 開(kāi)發(fā)之UILabel 或者 UIButton加下劃線(xiàn)鏈接

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

2021-03-23 16:18iOS開(kāi)發(fā)網(wǎng) IOS

這篇文章主要介紹了IOS 開(kāi)發(fā)之UILabel 或者 UIButton加下劃線(xiàn)鏈接的相關(guān)資料,需要的朋友可以參考下

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

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

方法一:

?
1
2
3
4
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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#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 到工程中,,然后將需要加下劃線(xiàn)的 Button 類(lèi)名改為 HyperlinksButton就可以了,提供了 setColor: 這個(gè)接口,可以設(shè)置下劃線(xiàn)顏色,代碼很簡(jiǎn)單,不解釋了。UILabel 同理可得。

示例結(jié)果:

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

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

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 四虎国产 | 婷婷色在线 | 欧洲一级 | 大吊操 | www久久精品| 欧美高清在线 | 调教车文 | 98精品全国免费观看视频 | 8x8x华人免费 | 日本全黄三级在线观看 | 日本高清在线看免费观看 | 久久91精品国产91久久户 | 亚洲精品乱码久久久久久蜜桃欧美 | 疯狂伦交1一6小说 | 我与肥熟老妇的性事 | xxxx性欧美极品另类 | 欧美精品国产一区二区三区 | 99精品在线 | 亚洲网站在线 | 亚洲国产视频网站 | 精品国产一区二区三区久久久蜜臀 | 国产精品视频第一区二区 | 成年人视频在线免费看 | 免费一级国产大片 | 青青在线视频观看 | 亚洲va韩国va欧美va天堂 | 久久中文字幕综合不卡一二区 | 艾秋麻豆果冻传媒老狼仙踪林 | 精品欧美小视频在线观看 | 黑人巨大精品战中国美女 | 国产清纯91天堂在线观看 | 性欧洲女人18| 欧美成人一区二区三区 | 俺去也亚洲色图 | 亚洲精品福利你懂 | 我的家教老师在线观看 | 舔到喷水 | 99ri在线精品视频在线播放 | 国产农村乱子伦精品视频 | 国产日韩精品欧美一区 | 久久精品国产亚洲AV热无遮挡 |