ios UILabel 的詳細使用及特殊效果

2021-06-12 02:59:28 字數 1991 閱讀 8337

uilabel *label = [[uilabelalloc] initwithframe:cgrectmake(0, 0, 75, 40)];   //宣告uilbel並指定其位置和長寬

label.backgroundcolor = [uicolorclearcolor];   //設定label的背景色,這裡設定為透明色。

label.font = [uifont fontwithname:@"helvetica-bold" size:13];   //設定label的字型和字型大小。

label.transform = cgaffinetransformmakerotation(0.1);     //設定label的旋轉角度

label.text = @「helloworld」;   //設定label所顯示的文字

label.textcolor = [uicolorwhitecolor];    //設定文字的顏色

label.shadowcolor = [uicolorcolorwithwhite:0.1falpha:0.8f];    //設定文字的陰影色彩和透明度。

label.shadowoffset = cgsizemake(2.0f, 2.0f);     //設定陰影的傾斜角度。

label.textalignment = uitextalignmentcenter;     //設定文字在label中顯示的位置,這裡為居中。

//換行技巧:如下換行可實現多行顯示,但要求label有足夠的寬度。

label.linebreakmode = uilinebreakmodewordwrap;     //指定換行模式

label.numberoflines = 2;    // 指定label的行數

//lable的旋轉

label.transform = cgaffinetransformmakerotation(0.2);     //設定label的旋轉角度

[self.view addsubview:label];    //將label載入

label的美化和特效:

這裡使用fxlabel來實現特殊效果,如上圖的「每日」二字就是用fxlabel來實現的,但要加入fxlbal.h和fxlabel.m兩個檔案,具體**如下。

iOS UILabel的使用方法

uilabel常用屬性 uilabel的建立 uilabel label uilabel alloc init 設定label的位置和大小 label.frame cgrectmake 50,50,100,30 設定文字 label.text hello world 設定背景色 label.back...

ios UILabel簡單使用方法

uilabel簡單使用方法 建立uilabel uilabel label uilabel alloc initwithframe cgrectmake 20,20,200,200 設定文字 label.text 文字內容 設定背景色 label.backgroundcolor uicolor bl...

ios UILabel 用法的總結

1 初始化 uilabel alabel uilabel alloc initwithframe cgrectmake 50,50,100,50 2 文字內容 位置預設是靠左的 alabel settext hello 設定字型顏色 alabel.textcolor uicolor bluecolo...