UI基礎(chǔ)控件

1.UILabel

文本內(nèi)容 ? ? ? ? ? ? ? ? ? ? ? ? text ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?@"abc”

背景顏色? ? ? ? ? ? ? ? ? ? ? ? ? backgroundColor? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? UIColor yellowColor

文本內(nèi)容顏色? ? ? ? ? ? ? ? ? ??textColor ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??UIColor?redColor

文本對(duì)齊方式? ? ? ? ? ? ? ? ? ??textAlignment(枚舉) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?NSTextAlignmentCenter

文本字體大小? ? ? ? ? ? ? ? ? ??font ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? UIFont?systemFontOfSize:20

文本行數(shù)??? ? ? ? ? ? ? ? ? ? ? ? ?numberOfLines ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??0

自適應(yīng)label尺寸 ? ? ? ? ? ? ? ?sizeToFit??? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?label?sizeToFit

斷行模式 ? ? ? ? ? ? ? ? ? ? ? ? ? lineBreakMode ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??NSLineBreakByTruncatingMiddle

陰影顏色???????????????????????????shadowColor? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??UIColor?cyanColor

陰影大小???????????????????????????shadowOffset? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CGSizeMake(2, 1)

設(shè)置邊框???????????????????????????layer.borderWidth? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?1

設(shè)置圓角???????????????????????????layer.cornerRadius? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?5

抹除圓角多余背景色 ? ? ? ??layer.masksToBounds? ? ? ? ? ? ? ? ? ? ? ? ? ??YES

文本位置大小?? ? ? ? ? ? ? ? ? ?label.frame? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CGRectMake(100, 100, 200, 200)

修改視圖的位置 ? ? ? ? ? ? ? ?center? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CGPointMake(500, 175)

1.1創(chuàng)建UILabel

UILabel?*label = [[UILabel?alloc]?initWithFrame:CGRectMake(100,?100,?200,?150)];

label.backgroundColor?= [UIColor?yellowColor];

[self.window?addSubview:label];

[label?release];


2.UIView

背景顏色? ? ? ? ? ? ? ? ? ? ? ? ? ? backgroundColor? ? ? ? ? ? UIColor yellowColor

透明度 ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ?alpha ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?0.5

位置大小 ? ? ? ? ? ? ? ? ? ? ? ? ? ?frame ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CGRectMake(200, 100, 150, 150)

父視圖把視圖放在上面?? ?bringSubviewToFront ? ? ? ??view2

父視圖把視圖放在下面 ? ? ??sendSubviewToBack ? ? ? ? ? view2

2.1創(chuàng)建UIView

UIView?*view1 = [[UIView?alloc]initWithFrame:CGRectMake(100,?100,?100,?100)];

view1.backgroundColor?= [UIColor?yellowColor];

[self.window?addSubview:view1];

[view1?release];


3.UIButton

位置大小? ? ? ? ? ? ? ? ? ? ? ? ? ? frame? ? ? ? ? ? ? ? ? ? ? CGRectMake(100, 100, 150, 70)

背景顏色?????????????????????????????backgroundColor ? ? ? ? ?? UIColor cyanColor

標(biāo)題 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? setTitle:?? forState: ? ?? @“確認(rèn)" ? ?UIControlStateNormal

標(biāo)題字體大小?????????????????????titleLabel.font ? ? ? ? ?? UIFont systemFontOfSize:25

圓角 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? layer.cornerRadius ? ? ? ??10

邊框? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?layer.borderWidth ? ? ? ?? 1

點(diǎn)擊方法?????????????addTarget:? action: ? ? ? ? ? ?? forControlEvents:

self ? ? ? @selector(click:) ? UIControlEventTouchUpInside

背景圖片 ? ? ? ? ? ? ? ? ? ? ? ? ? ?setBackgroundImage:?????????????????? forState:

[UIImage imageNamed:@"checked.png"]????UIControlStateNormal

3.1創(chuàng)建UIButton

UIButton?*button = [UIButton?buttonWithType:UIButtonTypeSystem];

button.frame?=?CGRectMake(100,?100,?100,?40);

[self.window?addSubview:button];

[button?setTitle:@"確認(rèn)"?forState:UIControlStateNormal];

button.layer.borderWidth?=?1;

button.layer.cornerRadius?=?10;

[button?addTarget:self?action:@selector(changePic:)?forControlEvents:UIControlEventTouchUpInside];

[button?setBackgroundImage:[UIImage?imageNamed:@"checked.png"]?forState:UIControlStateNormal];

-(void)changePic:(UIButton?*)button{

}


4.UITextField

背景顏色? ? ? ? ? ? ? ? backgroundColor? ? ? ? ? ? ? UIColor cyanColor

邊框????????????????????????????????????????????layer.borderWidth ? ? ? ? ?? 1

圓角????????????????????????????????????????????layer.cornerRadius ? ? ? ? ? 10

文本內(nèi)容?????????????????????????????????????text ? ? ? ? ? ? ? ? ? ? ? ? @"abc"

占位文本?????????????????????????????????????placeholder ? ? ? ? ? ? ? ?? @"占位字符"

文本顏色?????????????????????????????????????textColor ? ? ? ? ? ? ? ? ?? UIColor?yellowColor

文本位置?????????????????????????????????????textAlignment ? ? ? ? ? ? ?? NSTextAlignmentCenter

密碼圓點(diǎn)?????????????????????????????????????secureTextEntry ? ? ? ? ? ?? YES

鍵盤(pán)類(lèi)型?????????????????????????????????????keyboardType ? ? ? ? ? ? ? ? UIKeyboardTypeNumberPad

return樣式? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?returnKeyType ? ? ? ? ? ? ?? UIReturnKeySearch

清除按鈕樣式? ? ? ? ? ? ? ? ? ? ? ? ? ? ??clearButtonMode? ? ? ? ? ? ??UITextFieldViewModeAlways

彈出視圖.默認(rèn)是鍵盤(pán) ? ? ? ? ? ? ? ?inputView ? ? ? ? ? ? ? ? ?? view

輔助視圖 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? inputAccessoryView ? ? ? ? ? view

4.2創(chuàng)建UITextField

UITextField?*textField = [[UITextField?alloc]?initWithFrame:CGRectMake(100,?100,?200,40)];

textField.backgroundColor?= [UIColor?cyanColor];

[self.window?addSubview:textField];

[textField?release];

textField.delegate?=?self;

-(BOOL)textFieldShouldReturn:(UITextField?*)textField{

NSLog(@"測(cè)試return按鈕");

//回收鍵盤(pán) ? (改變第一響應(yīng)者)

[textField?resignFirstResponder];

return?YES;

}

-(BOOL)textFieldShouldClear:(UITextField?*)textField{

NSLog(@"測(cè)試清除按鈕");

return?YES;

}


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容