自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iOS開(kāi)發(fā):自定義帶下劃線文本的UIButton

移動(dòng)開(kāi)發(fā) iOS
本文為各位51CTO的網(wǎng)友朋友們介紹了iOS開(kāi)發(fā)實(shí)戰(zhàn)中如何自定義帶下劃線文本的UIButton,文章比較簡(jiǎn)潔,直接將Uiunderlinedbutton.h和Uiunderlinedbutton.m的代碼整理出來(lái),各位讀者可以親自實(shí)現(xiàn)一邊這些代碼,在慢慢消化了解。

Uiunderlinedbutton.h代碼

  1. @interface UIUnderlinedButton : UIButton { 
  2. + (UIUnderlinedButton *) underlinedButton; 
  3. @end 

Uiunderlinedbutton.m代碼

  1. @implementation UIUnderlinedButton 
  2.  
  3. + (UIUnderlinedButton*) underlinedButton { 
  4. UIUnderlinedButton* button = [[UIUnderlinedButton alloc] init]; 
  5. return [button autorelease]; 
  6.  
  7. - (void) drawRect:(CGRect)rect { 
  8. CGRect textRect = self.titleLabel.frame; 
  9.  
  10. // need to put the line at top of descenders (negative value) 
  11. CGFloat descender = self.titleLabel.font.descender; 
  12.  
  13. CGContextRef contextRef = UIGraphicsGetCurrentContext(); 
  14.  
  15. // set to same colour as text 
  16. CGContextSetStrokeColorWithColor(contextRef, self.titleLabel.textColor.CGColor); 
  17.  
  18. CGContextMoveToPoint(contextRef, textRect.origin.x, textRect.origin.y + textRect.size.height + descender); 
  19.  
  20. CGContextAddLineToPoint(contextRef, textRect.origin.x + textRect.size.width, textRect.origin.y + textRect.size.height + descender); 
  21.  
  22. CGContextClosePath(contextRef); 
  23. CGContextDrawPath(contextRef, kCGPathStroke); 
  24. @end 

 

責(zé)任編輯:閆佳明 來(lái)源: apkbus
相關(guān)推薦

2023-11-29 18:11:17

Python代碼

2021-08-08 22:27:13

Python下劃線方法

2011-08-02 11:17:13

iOS開(kāi)發(fā) View

2021-12-26 22:55:26

Python下劃線編程

2021-07-31 19:21:34

Python下劃線數(shù)值

2020-09-22 09:41:48

Python下劃線開(kāi)發(fā)

2010-03-04 10:35:51

Python下劃線

2013-06-27 11:10:01

iOS開(kāi)發(fā)自定義UISlider

2024-08-16 22:00:38

2023-11-09 08:55:17

Python雙下劃線

2009-06-08 20:13:36

Eclipse自定義控

2014-05-08 10:36:59

CSS單詞連字符

2013-07-18 16:09:10

自定義iOS狀態(tài)欄iOS開(kāi)發(fā)iOS學(xué)習(xí)

2009-06-24 15:13:36

自定義JSF組件

2011-12-26 10:11:08

JSP

2012-06-01 11:02:33

2017-10-25 14:07:54

APPiOSxcode

2013-05-30 15:53:17

iOS開(kāi)發(fā)iOS SDKPopver

2021-01-20 08:58:39

iOS 14桌面圖標(biāo)快捷指令

2020-10-24 11:09:35

Python下劃線用法
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)