UI常用控件
//
// ?Created by lanou on 16/7/10.
// ?Copyright ? 2016年pingguo. All rights reserved.
//
#import"ViewController.h"
@interfaceViewController()
@property(nonatomic,strong)UILabel*titleLabel;
@property(nonatomic,strong)UIButton*leftBtn;
@property(nonatomic,strong)UIButton*rightBtn;
@property(nonatomic,strong)UIImageView*myImageView;
@property(nonatomic,strong)NSArray*imageNames;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
self.imageNames=@[@"biaoqingdi",@"bingli",@"chiniupa",@"danteng",@"wangba"];
//創(chuàng)建并初始化按鈕圖片及文本
//表明文本的位置
self.titleLabel=[[UILabelalloc]initWithFrame:CGRectMake(160,60,150,30)];
//文本內(nèi)容
self.titleLabel.text=@"biaoqingdi";
//將文本添加到視圖
[self.viewaddSubview:self.titleLabel];
//表明左按鈕的位置
self.leftBtn=[[UIButtonalloc]initWithFrame:CGRectMake(20,150,45,45)];
//關(guān)掉交互
self.leftBtn.userInteractionEnabled=NO;
//加載左按鈕的圖片
UIImage*leftImage=[UIImageimageNamed:@"left_disable"];
//左按鈕的背景及按下狀態(tài)
[self.leftBtnsetBackgroundImage:leftImageforState:(UIControlStateNormal)];
//將左按鈕添加到視圖
[self.viewaddSubview:self.leftBtn];
//表明圖片的位置
self.myImageView=[[UIImageViewalloc]initWithFrame:CGRectMake(85,100,200,200)];
//加載圖片
UIImage*image=[UIImageimageNamed:@"biaoqingdi"];
//設置myimageview顯示的圖片
self.myImageView.image=image;
//將圖片添加到視圖
[self.viewaddSubview:self.myImageView];
//以下同理
self.rightBtn=[[UIButtonalloc]initWithFrame:CGRectMake(305,150,45,45)];
UIImage*rightImage=[UIImageimageNamed:@"right_normal"];
[self.rightBtnsetBackgroundImage:rightImageforState:(UIControlStateNormal)];
[self.viewaddSubview:self.rightBtn];
//創(chuàng)立按鈕監(jiān)聽
[self.rightBtnaddTarget:selfaction:@selector(rightBtnAction)forControlEvents:(UIControlEventTouchUpInside)];
[self.leftBtnaddTarget:selfaction:@selector(leftBtnAction)forControlEvents:(UIControlEventTouchUpInside)];
oc基本語法
//
// ?Created by lanou on 16/7/9.
// ?Copyright ? 2016年pingguo. All rights reserved.
//
#import
intmain(intargc,constchar* argv[]) {
@autoreleasepool{
// insert code here...
NSLog(@"Hello, World!");
? OC基本語法
//整型
NSIntegera =10;
NSLog(@"a=%ld",a);
CGFloat ?b =2.3;
NSLog(@"b=%.2f",b);
BOOLflag =YES;
NSString*str=@"abcde";
NSLog(@"str=%@",str);
NSLog(@"str的長度=%ld",str.length);
if([strisEqualToString:@"abcde"]) {
NSLog(@"是的");
}
if([strhasPrefix:@"a"]) {
NSLog(@"前綴等于a");}
if([strhasSuffix:@"e"]) {
NSLog(@"后綴等于e");
}
NSString*str1=[NSStringstringWithFormat:@"%@++++",@"im"];
NSLog(@"str1=%@",str1);
}
return0;
}
oc基礎語法:
//
// ?Created by lanou on 16/7/9.
// ?Copyright ? 2016年pingguo. All rights reserved.
//
#import
intmain(intargc,constchar* argv[]) {
@autoreleasepool{
// insert code here...
NSLog(@"Hello, World!");
NSArray*array1=@[@"a",@"b",@"c",@"d"];
NSLog(@"array1=%@",array1);
NSLog(@"count=%ld",array1.count);
NSString*str = array1[0];
NSLog(@"str=%@",str);
NSMutableArray*mutableArray =[NSMutableArrayarrayWithObjects:@"1",@"2",@"3",@"4",nil];
NSLog(@"mutable Array=%@",mutableArray);
[mutableArrayaddObject:@"5"];
NSLog(@"已添加----%@",mutableArray);
[mutableArrayremoveObject:@"3"];
NSLog(@"已移除----%@",mutableArray);
NSDictionary*dict =@{@"key1":@"value1",@"key2":@"value2",@"key3":@"value3"};
NSLog(@"dict=%@",dict);
NSString*string=[dictobjectForKey:@"key1"];
NSLog(@"string=%@",string);
NSLog(@"allkeys=%@,allvalues=%@",dict.allKeys,dict.allValues);
}
return0;
}