內(nèi)容比較少艺骂,用的也比較少茄厘,稍微記錄一下。都是 UIControl 的 子類铃绒,UIControl 需要好好研究一下。
UISwitch 簡單示例
// 寫個默認(rèn)的背景螺捐,對比下開關(guān)設(shè)置的rect
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 100, 100)];
backgroundView.backgroundColor = [UIColor grayColor];
[self.view addSubview:backgroundView];
// seitch 大小固定颠悬,只與(x,y) 有關(guān)
UISwitch *aswitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 200, 100, 100)];
aswitch.backgroundColor = [UIColor yellowColor];
[self.view addSubview:aswitch];
// 幾個屬性
aswitch.thumbTintColor = [UIColor orangeColor]; // 滑塊
aswitch.onTintColor = [UIColor greenColor]; // on
aswitch.tintColor = [UIColor redColor]; // off(背景)
// 設(shè)置開關(guān)
[aswitch setOn:!aswitch.isOn animated:YES];
// 下面的設(shè)置無效了,也沒有提示...在文檔中才有說 iOS7 之后無效(實在是這玩意沒啥用岸ㄑ)
aswitch.offImage = [UIImage imageNamed:@"iconfont-off"];
aswitch.onImage = [UIImage imageNamed:@"iconfont-on"];
UISlider
// 滑塊 高度已定赔癌,內(nèi)容也會自動調(diào)整,
self.aslider = [[UISlider alloc] initWithFrame:CGRectMake(10, 100, CGRectGetWidth(self.view.bounds) - 20, 100)];
[self.view addSubview:self.aslider];
self.aslider.minimumValue = 100;// 最小值
self.aslider.maximumValue = 900;// 最大值
self.aslider.value = 200.;// 當(dāng)前值澜沟,一般用來獲取
self.aslider.minimumTrackTintColor = [UIColor redColor];// 已完成的顏色
self.aslider.maximumTrackTintColor = [UIColor greenColor];// 未完成的顏色
self.aslider.thumbTintColor = [UIColor blueColor];// 滑塊顏色
self.aslider.minimumValueImage = [UIImage imageNamed:@"iconfont-on"];// 左側(cè)圖片灾票,滑塊,也會對應(yīng)變短
self.aslider.maximumValueImage = [UIImage imageNamed:@"iconfont-off"];// 右側(cè)圖片
self.aslider.continuous = YES; // yes 時:value 變化就會通知茫虽;no 時:拖動結(jié)束才通知
// 根據(jù)不同的state 設(shè)置圖片刊苍,并獲取
// 注意這里的image 不做處理的話是隨著滑塊的移動而拉伸的,可以考慮重寫濒析,不使用拉伸的imageView
[self.aslider setThumbImage:[UIImage imageNamed:@"iconfont-on"] forState:UIControlStateNormal];
[self.aslider setMinimumTrackImage:[UIImage imageNamed:@"iconfont-on"] forState:UIControlStateNormal];
[self.aslider setMaximumTrackImage:[UIImage imageNamed:@"iconfont-off"] forState:UIControlStateNormal];
// 對應(yīng)有獲取圖片正什,就不寫了...
// 添加事件,value 變化号杏。
[self.aslider addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventValueChanged];
// 重寫一個 舉例
-(CGRect)minimumValueImageRectForBounds:(CGRect)bounds; {
for(UIView *view in [self subviews]) {
if ([view isKindOfClass:[UIImageView class]]) {
view.clipsToBounds = YES;
view.contentMode = UIViewContentModeBottomLeft;
// max 類似
}
}
return bounds;
}
UIDatePick
- 一般日期選擇
self.datePick = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 100, CGRectGetWidth(self.view.bounds), 200)];
[self.view addSubview:self.datePick];
self.datePick.datePickerMode = UIDatePickerModeDateAndTime;
/*
typedef NS_ENUM(NSInteger, UIDatePickerMode) {
UIDatePickerModeTime, // Displays hour, minute, and optionally AM/PM designation depending on the locale setting (e.g. 6 | 53 | PM)
UIDatePickerModeDate, // Displays month, day, and year depending on the locale setting (e.g. November | 15 | 2007)
UIDatePickerModeDateAndTime, // Displays date, hour, minute, and optionally AM/PM designation depending on the locale setting (e.g. Wed Nov 15 | 6 | 53 | PM)
UIDatePickerModeCountDownTimer, // Displays hour and minute (e.g. 1 | 53)
};
*/
// 設(shè)置 時間選擇 范圍
self.datePick.minimumDate = [NSDate dateWithTimeIntervalSince1970:0];
self.datePick.maximumDate = [NSDate date];
// 一些設(shè)置婴氮,看另一篇把 分別是:本地,時區(qū)盾致,歷法
self.datePick.locale = [NSLocale currentLocale];
self.datePick.timeZone = [NSTimeZone defaultTimeZone];
self.datePick.calendar = [NSCalendar currentCalendar];
// 獲取 和 設(shè)置時間
NSDate *selectDate = self.datePick.date;
[self.datePick setDate:[NSDate dateWithTimeIntervalSinceNow:-3600] animated:YES];
// 添加事件
[self.datePick addTarget:self action:@selector(testAction) forControlEvents:UIControlEventValueChanged];
- 倒計時
就是: UIDatePickerMode:UIDatePickerModeCountDownTimer
self.datePick.minuteInterval = 1.;// 顯示的時間間隔 n分鐘
self.datePick.countDownDuration = 120;// 剩余時間(還要自己寫 --);
UISegmentedControl
NSArray *items = @[@"1",@"2222",@"3",@"444"];
self.segmentedControl = [[UISegmentedControl alloc] initWithItems:items];
self.segmentedControl.frame = CGRectMake(10, 100, 300, 66);
[self.view addSubview:self.segmentedControl];
self.segmentedControl.tintColor = [UIColor redColor];// 顏色
self.segmentedControl.apportionsSegmentWidthsByContent = YES;// 默認(rèn)NO:平均分主经; YES: 寬度自動調(diào)整。
NSInteger selectindex = self.segmentedControl.selectedSegmentIndex;// 選中項
NSLog(@"%zi",self.segmentedControl.selectedSegmentIndex);
// 移除 插入
[self.segmentedControl removeSegmentAtIndex:9 animated:YES];
[self.segmentedControl removeAllSegments];
[self.segmentedControl insertSegmentWithTitle:@"555" atIndex:0 animated:YES];
[self.segmentedControl insertSegmentWithTitle:@"555" atIndex:0 animated:YES];
[self.segmentedControl insertSegmentWithTitle:@"555" atIndex:0 animated:YES];
[self.segmentedControl insertSegmentWithTitle:@"555" atIndex:0 animated:YES];
// 設(shè)置屬性 內(nèi)容 寬 偏移 可用性
[self.segmentedControl setTitle:@"1231" forSegmentAtIndex:0];
[self.segmentedControl setWidth:100 forSegmentAtIndex:0];
[self.segmentedControl setContentOffset:CGSizeMake(-40, 20) forSegmentAtIndex:0];
[self.segmentedControl setEnabled:YES forSegmentAtIndex:0];
// 對應(yīng)有獲取绰上,也不寫了
// 背景
[self.segmentedControl setBackgroundImage:[UIImage imageNamed:@"iconfont-off"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
// 屬性字符串
[self.segmentedControl setTitleTextAttributes:@{NSUnderlineStyleAttributeName:@1} forState:UIControlStateNormal];
// 內(nèi)容 偏移 type 表示那些需要設(shè)置
[self.segmentedControl setContentPositionAdjustment:UIOffsetMake(10, 20) forSegmentType:UISegmentedControlSegmentCenter barMetrics:UIBarMetricsDefault];
// 添加事件
[self.segmentedControl addTarget:self action:@selector(testAction) forControlEvents:UIControlEventValueChanged];
// title 也可以是 image
UIPageControl
一般結(jié)合 scrolleView 使用旨怠,簡單也一下本身的使用。
self.apageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
[self.view addSubview:self.apageControl];
self.apageControl.numberOfPages = 5;// 總頁數(shù)
self.apageControl.currentPage = 2;// 當(dāng)前頁
self.apageControl.hidesForSinglePage = YES;// 單頁時蜈块,隱藏
self.apageControl.defersCurrentPageDisplay = YES;// 相當(dāng)于 標(biāo)記 需要更新page鉴腻,結(jié)合下面的使用
[self.apageControl updateCurrentPageDisplay];// 更新 page
self.apageControl.pageIndicatorTintColor = [UIColor redColor];// 未選擇的點
self.apageControl.currentPageIndicatorTintColor = [UIColor greenColor];// 選中的點
// 添加 點擊圓點的 事件
[self.apageControl addTarget:self action:@selector(testAction) forControlEvents:UIControlEventValueChanged];
1