//图像视图 UIImageView
self.aView = [[[UIImageViewalloc] initWithFrame:CGRectMake(20, 60, 280, 400)]autorelease];
self.aView.image = [UIImageimageNamed:@"akgo"];//设置显示图片,如果图片格式为png,后辍名可不写
self.aView.userInteractionEnabled =NO;//是否响应触摸事件,默认值为NO.一定要记住!!!
[selfaddSubview:self.aView];
self.aView.image = [UIImageimageNamed:@"akgo"];//重置图片
self.aView.backgroundColor = [UIColoryellowColor];//设置背景
self.aView.contentMode = UIViewContentModeCenter;//设置内容填充模式,默认是UIViewContentModeScaleToFill
/**
UIViewContentModeScaleToFill //缩放以填充,图片可能会变形
UIViewContentModeScaleAspectFit //缩放以显示全部,比例不变
UIViewContentModeScaleAspectFill //缩放显示并填满,比例不变,图片可能部分未显示
UIViewContentModeCenter //内容大小不变,居中显示
UIViewContentModeTop //内容大小不变,靠顶部显示
UIViewContentModeBottom //内容大小不变,靠底部显示
UIViewContentModeLeft //内容大小不变,靠左边显示
UIViewContentModeRight //内容大小不变,靠右边显示
UIViewContentModeTopLeft //内容大小不变,靠顶部左边显示
UIViewContentModeTopRight //内容大小不变,靠顶部右边显示
UIViewContentModeBottomLeft //内容大小不变,靠底部左边显示
UIViewContentModeBottomRight //内容大小不变,靠顶部右边显示
//开关 UISwitch
UISwitch *aSwitch = [[[UISwitchalloc] initWithFrame:CGRectMake(20, 20, 10, 10)]autorelease];//这里的宽,高没有实际意义,由系统自定义
aSwitch.onTintColor = [UIColorgreenColor];//打开开关时的背景色
aSwitch.tintColor = [UIColorgrayColor];//关闭开关时的背景色
aSwitch.thumbTintColor = [UIColoryellowColor];//开关滑块的颜色
aSwitch.on = NO;//设置开关关闭状态
[aSwitch addTarget:selfaction:@selector(switchAction:)forControlEvents:UIControlEventValueChanged];//开关值改变的响应方法
[self addSubview:aSwitch];
- (void)switchAction:(UISwitch*)aSwitch
{
if (YES == aSwitch.on)
{
NSLog(@"开关已经打开");
}
else
{
NSLog(@"开关已经关闭");
}
}
//滑块 UISlider
UISlider *aSlider = [[[UISlideralloc] initWithFrame:CGRectMake(50, 50, 220, 10)]autorelease];这里的高没有实际意义,由系统自定义
aSlider.value = 0.0;//设置起始值
aSlider.minimumValue = 0.0;//设置最小值
aSlider.maximumValue = 1.0;//设置最大值
[aSlider addTarget:selfaction:@selector(sliderAction:)forControlEvents:UIControlEventValueChanged];//设置滑块改变响应方法
[self addSubview:aSlider];
//进度条 UIProgressView
self.progressView = [[[UIProgressViewalloc] initWithFrame:CGRectMake(50, 50, 220, 100)]autorelease];//这里的高度由系统自定义
self.progressView.progress = 0.0;//设置初始值
self.progressView.progressTintColor = [UIColoryellowColor];//设置进度背景颜色
self.progressView.trackTintColor = [UIColorgreenColor];//设置轨道背景颜色
[selfaddSubview:self.progressView];
//模态对话框 UIAlertView
UIAlertView *alertView = [[UIAlertViewalloc] initWithTitle:@"提示"
message:@"当前无网络,请检查你的网络设置"
delegate:nil
cancelButtonTitle:@"好的"
otherButtonTitles:nil];
[alertView show];
[alertView release];
//表单弹出框 UIActionSheet
UIActionSheet *sheet = [[UIActionSheetalloc] initWithTitle:@"分享"
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:nil
otherButtonTitles:@"新浪微博",@"腾讯微博",@"微信-朋友圈",@"邮件分享",@"短信分享",nil];
[sheet showInView:self];//指定弹出框的父视图
[sheet release];