iOS開發之三 常用控制項 UILabel的使用

2021-06-21 11:52:21 字數 1842 閱讀 3001

uilabel 一般用來顯示文字內容。

常用的屬性如下:

@property(nonatomic,copy)   nsstring           *text;           // 文字的內容,預設為 nil

@property(nonatomic,retain) uifont *font; // 文字的字型,預設為nil (system font 17 plain)

@property(nonatomic,retain) uicolor *textcolor; // 文字的顏色,預設為 nil (text draws black)

@property(nonatomic,retain) uicolor *shadowcolor; // 文字的陰影,預設為 nil (沒有陰影),如果要設定陰影,則需要設定偏移量

@property(nonatomic) cgsize shadowoffset; // 設定偏移量

@property(nonatomic) nstextalignment textalignment; // 文字對齊方式,預設左對齊

@property(nonatomic) nslinebreakmode linebreakmode; // 文字超出frame時的擷取方式

@property(nonatomic,retain) uicolor *highlightedtextcolor; // 文字選中時的高亮顏色

@property(nonatomic,getter=ishighlighted) bool highlighted; // 是否存在高亮,預設為no

@property(nonatomic,getter=isuserinteractionenabled) bool userinteractionenabled; // 使用者互動是否開啟,預設為no。

uilabel的用法,例項**:

uilabel *label = [[uilabel alloc] initwithframe:cgrectmake(90, 100, 140, 40)];

//背景為紅色

label.backgroundcolor = [uicolor redcolor];

//文字內容

label.text = @"測試文字";

//文字字型

label.font = [uifont systemfontofsize:14];

//文字行數

label.numberoflines = 0; // no limit

//label寬度不夠時,對文字進行打斷的方式

label.linebreakmode = nslinebreakbytruncatinghead;

//文字的陰影 顏色

label.shadowcolor = [uicolor yellowcolor];

//文字的陰影偏移量

label.shadowoffset = cgsizemake(-2, 2);

//文字對齊方式,引數是列舉型別,有左中右三種對齊方式

label.textalignment = nstextalignmentcenter;

//文字的字型顏色

label.textcolor = [uicolor bluecolor];

//根據文字自動調整label的寬度和高度

[label sizetofit];

一些好看的uilabel效果:

驅動開發之三 常用API簡介

1.driver object的結構體如下 typedef struct driver object cshort type cshort size pdevice object deviceobject ulong flags pvoid driverstart ulong driversize ...

iOS動畫開發之三 UIView的轉場切換

前兩篇部落格中,我們分別介紹了uiview動畫的兩種使用方式,分別為,帶block的方式 傳統的屬性配置的方式 通過uiview動畫的類方法,我們可以十分方便的使view 某些屬性改變的同時擁有動畫效果。這篇部落格主要討論view切換的動畫操作。兩個方法 void transitionwithvie...

iOS開發控制項基礎

一 使用plist檔案 使用plist檔案的目的 將資料和 分離。載入方法 nsstring path nsbundle mainbundle pathforresource imagedata oftype plist nsarray imagelist nsarray arraywithcont...