寫乙個新類
underlinelabel :
uilabel
- (void)drawrect:(cgrect)rect
在需要的地方用
underlinelabel初始化生成即可.
首先要匯入
#import
//虛線
cashapelayer *shapelayer = [cashapelayer layer];
[shapelayer setbounds:self.bounds];
[shapelayer setposition:self.center];
[shapelayer setfillcolor:[[uicolor clearcolor] cgcolor]];
// 設定虛線顏色為black
[shapelayer setstrokecolor:[[uicolor colorwithred:223/255.0 green:223/255.0 blue:223/255.0 alpha:1.0f] cgcolor]];
// 3.0f設定虛線的寬度
[shapelayer setlinejoin:kcalinejoinround];
// 3=線的寬度 1=每條線的間距
[shapelayer setlinedashpattern:[nsarray arraywithobjects:[nsnumber numberwithint:1],[nsnumber numberwithint:1],nil]];
// setup the path
cgmutablepathref path = cgpathcreatemutable();
cgpathmovetopoint(path, null, 100, 67); //100 ,67 初始點 x,y
cgpathaddlinetopoint(path, null, 310,67); //67終點x,y
[shapelayer setpath:path];
cgpathrelease(path);
//新增到容器中
[[self layer] addsublayer:shapelayer];
此處 self是乙個view
UILbale 畫刪除線或下劃線等
乙個帶刪除線的文字標籤,繼承自uilabel 自繪 步驟如下 1,重寫控制項的drawrect方法 2,首先得到上下文物件 3,設定顏色,並指定是填充 fill 模式還是筆刷 stroke 模式 4,在上下文中指定刪除線的起點 含x,y 5,根據標籤文字的字型,確定文字的長度 即將被畫的線條的長度 ...
如何將鏈結的下劃線做成虛線?
瀏覽器的hover 實現的是實現效果,那麼如何將鏈結的下劃線做成虛線,或者在link與hover不同狀態,下劃線會從虛線到實線的變化呢?設定text decoration none。也就是去除了鏈結的下劃線。然後再給鏈結加下邊框線,設定下邊框線不同的寬度 線型 顏色,就可以實現 下劃線 變成多樣效果...
IOS之UILabel新增下劃線
ios之uilabel新增下劃線,有需要的朋友可以參考下。uilabel新增下劃線的方式有多種方法,這裡介紹兩種常用的方法.1.利用uilabel的屬性來新增下劃線 uilabel label uilabel alloc initwithframe cgrectmake 0,0,320,40 nsm...