IOS开发之UI设计---控件(UISegmentController,UISlider,UISwitch,UIActivityIndicatorView,UIProgressView)以及触摸事件(UITouch)
UISegmentedControl:(多段选择器)
NSArray *arr = [NSArrayarrayWithObjects:@"Lucy",@"Lily",@"OK", nil];
UISegmentedControl *segCtrl = [[UISegmentedControlalloc]initWithItems:arr];
[segCtrl setFrame:CGRectMake(0, 0, 210, 40)];
[segCtrl addTarget:selfaction:@selector(click:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segCtrl];
[segCtrl release];
//手动插入一个segmentedControl
- (void)insertSegmentWithTitle:(NSString *)title atIndex:(NSUInteger)segment animated:(BOOL)animated; // insert before segment number. 0..#segments. value pinned
- (UIView *)viewWithTag:(NSInteger)tag; // recursive search. includes self 从视图上获取tag为某个值的视图
//进度条
UISlider *slider = [[UISlideralloc]initWithFrame:CGRectMake(0, 40, 240, 30)];
[slider addTarget:segCtrl action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
slider.tag = 2;
slider.maximumValue = 100;
slider.minimumValue = 0;
[self.view addSubview:slider];
[slider release];
//开关
UISwitch *_switch = [[UISwitchalloc]initWithFrame:CGRectMake(0, 80, 50, 30)];
[_switch addTarget:self action:@selector(switchChange:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:_switch];
_switch.thumbTintColor = [UIColor purpleColor];
//设置UISwitch的背景色
_switch.tintColor = [UIColor cyanColor];
_switch.onTintColor = [UIColor brownColor];
[_switch release];
//环形进度条
UIActivityIndicatorView *acView = [[UIActivityIndicatorViewalloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
/*UIActivityIndicatorViewStyleWhiteLarge,
UIActivityIndicatorViewStyleWhite,
UIActivityIndicatorViewStyleGray,
*/
[acView setFrame:CGRectMake(0, 120, 60, 30)];
acView.tag = 5;
acView.hidesWhenStopped = YES;//设置停止转圈后,隐藏
[self.view addSubview:acView];
[acView release];
//进度条(推荐使用)
UIProgressView *proView = [[UIProgressViewalloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
[proView setFrame:CGRectMake(0, 170, 260, 20)];
proView.tag = 6;
proView.progress = 1.0;
[proView setProgressTintColor:[UIColorredColor]];
[proView setTrackTintColor:[UIColorblueColor]];
[self.view addSubview:proView];
[proView release];
//步进器— 每一次都增加或者减少一个特定的值
UIStepper *step = [[UIStepperalloc]initWithFrame:CGRectMake(0, 200, 60, 30)];
[step addTarget:selfaction:@selector(stepChanged:) forControlEvents:UIControlEventValueChanged];// 事件状态UIControlEventValueChanged
step.minimumValue = 0; //步进器的最小值
step.maximumValue = 100;//步进器的最大值
step.stepValue = 5;//每一步增加或者减少的值
step.wraps = YES; //是否循环
UITouch : NSObject
- (CGPoint)locationInView:(UIView *)view; //当前视图在屏幕中所处的位置
- (CGPoint)previousLocationInView:(UIView *)view; //
UITextView : UIScrollView
//导入第三方库文件
//给_textView设置一个圆角边
//控件边框的颜色
_textView.layer.borderColor = [UIColorblackColor].CGColor;
//设置控件边框圆角弧度
_textView.layer.cornerRadius = 8.0;
//设置控件边框线条宽度
_textView.layer.borderWidth = 2.0;
UITextViewDelegate:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;
- (BOOL)textViewShouldEndEditing:(UITextView *)textView;
- (void)textViewDidBeginEditing:(UITextView *)textView;
- (void)textViewDidEndEditing:(UITextView *)textView;
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;