day7---UI控件瀏覽

/*************** 1.分段選取器 ********************/
//參數數組里存放的是字符串(標題)或者圖片
UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"電視劇",@"電影",@"綜藝",@"動漫"]];
segment.frame = CGRectMake(50, 100, screenBounds.size.width-100, 40);

//設置哪個分段處于選中狀態
segment.selectedSegmentIndex = 0;

[segment addTarget:self action:@selector(segmentValueChange:) forControlEvents:UIControlEventValueChanged];

//設置內容渲染顏色
segment.tintColor = [UIColor redColor];
[self.view addSubview:segment];

/***************** 2.UISlider滑塊*************/

UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(50, 200, screenBounds.size.width-100, 40)];
//設置最小值
slider.minimumValue = 1;
//設置最大值
slider.maximumValue = 10;
//設置當前顯示的value
slider.value = 5;
//設置圖片
slider.minimumValueImage = [UIImage imageNamed:@"1"];
slider.maximumValueImage = [UIImage imageNamed:@"2"];
[slider setThumbImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
//設置顏色

// slider.minimumTrackTintColor = [UIColor redColor];
// slider.maximumTrackTintColor = [UIColor blackColor];
// slider.thumbTintColor = [UIColor redColor];

[slider addTarget:self action:@selector(sliderValueChange:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:slider];


UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backItem;

/********************3. UISwitch **************/
UISwitch *sw = [[UISwitch alloc] initWithFrame:CGRectMake(150, 100, 10, 10)];
//設置開啟狀態
sw.on = YES;
//設置相關顏色
sw.onTintColor = [UIColor redColor];
sw.thumbTintColor = [UIColor greenColor];
sw.tintColor = [UIColor blackColor];
//設置圓角半徑
sw.backgroundColor = [UIColor yellowColor];
sw.layer.cornerRadius = 15;
sw.layer.masksToBounds = YES;
//添加事件
[sw addTarget:self action:@selector(swValueChange:) forControlEvents:UIControlEventValueChanged];

[self.view addSubview:sw];

/***4. UIActivityIndicatorView等待加載符 *****/
UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activity.center = self.view.center;
//讓等待加載符 ,開始加載
// [activity startAnimating];
// activity.backgroundColor = [UIColor blackColor];
//停止加載
// [activity stopAnimating];
//設置顏色
activity.color = [UIColor blueColor];
activity.tag = 100;
[self.view addSubview:activity];

self.title = @"步進器和進度條";
/*********** 5.步進器 *************/
UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(100, 100, 1, 1)];
stepper.center = CGPointMake(screenBounds.size.width/2, 100);
//設置最小值
stepper.minimumValue = 0;
//設置最大值
stepper.maximumValue = 10;
//設置步長
stepper.stepValue = 1;
//添加事件
[stepper addTarget:self action:@selector(stepperValueChange:) forControlEvents:UIControlEventValueChanged];
//設置顏色
stepper.tintColor = [UIColor orangeColor];
[self.view addSubview:stepper];

/************ 6.進度條UIProgressView ********/
UIProgressView *progress = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
progress.frame = CGRectMake(50, 200, screenBounds.size.width-100, 9);
//當前進度條的進度,范圍(0-1之間)
progress.progress = 0;
//設置顏色
progress.progressTintColor = [UIColor redColor];
progress.tag = 100;
progress.trackTintColor = [UIColor whiteColor];

[self.view addSubview:progress];

//********************** 7.創建警告框
// UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"??" message:@"您確定要自殺嗎?" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES",@"考慮一下",@"讓我想會兒", nil];
//
// [alertView show];//顯示出來

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"信息" message:@"請輸入用戶名和密碼" delegate:self cancelButtonTitle:@"返回" otherButtonTitles:@"確定", nil];
//設置警告框的樣式
alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[alertView show];

//************************ 8.操作列表對象
-(void)creatAlerView{

// UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"??" message:@"您確定要自殺嗎?" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES",@"考慮一下",@"讓我想會兒", nil];
//
// [alertView show];//顯示出來

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"信息" message:@"請輸入用戶名和密碼" delegate:self cancelButtonTitle:@"返回" otherButtonTitles:@"確定", nil];
//設置警告框的樣式
alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[alertView show];

}

iOS8.0之后的警告框和操作列表對象
-(void)creatAlerView{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"信息" message:@"請輸入用戶名和密碼" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"返回" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
    NSLog(@"返回按鈕被點擊了");
}];

UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    //打印出輸入的用戶名和密碼的信息
    UITextField *field1 = [alert.textFields firstObject];
    UITextField *field2 = alert.textFields[1];
    NSLog(@"您輸入的用戶名是:%@ 密碼是:%@",field1.text,field2.text);
    
}];

[alert addAction:action1];
[alert addAction:action2];

//為UIAlertController添加文本框
//可以向對話框添加任意數目的UITextField類型的對象,并且在Block語句里面使用所有的UITextField的屬性
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
    textField.placeholder = @"請輸入用戶名:";
    textField.textColor = [UIColor redColor];
    textField.font = [UIFont systemFontOfSize:20];
    
}];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
    textField.placeholder = @"請輸入密碼:";
    textField.secureTextEntry = YES;
    textField.font = [UIFont systemFontOfSize:20];
    
}];



[self presentViewController:alert animated:YES completion:nil];

}

-(void)creatActionSheet{

UIAlertController *sheet = [UIAlertController alertControllerWithTitle:nil message:@"分享" preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"微信分享" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
    NSLog(@"微信分享");
}];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"QQ分享" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    NSLog(@"QQ分享");
}];
UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"微博分享" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    NSLog(@"微博分享");
}];

UIAlertAction *action4 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    NSLog(@"取消");
}];


[sheet addAction:action1];
[sheet addAction:action2];
[sheet addAction:action3];
[sheet addAction:action4];

[self presentViewController:sheet animated:YES completion:nil];

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • { 11、核心動畫 需要簽協議,但是系統幫簽好 一、CABasicAnimation 1、創建基礎動畫對象 CAB...
    CYC666閱讀 1,591評論 2 4
  • //準備工作 1.刪除Main 2.ARC->MRC(YES->No) 3.刪除文件(ViewConTroller...
    愛吃芒果的淼小豬閱讀 405評論 1 1
  • 1.UILabel 1) label.frame //CGRectMake(x, y, width, he...
    青春flame閱讀 670評論 0 2
  • 用法: 先添加指針視圖,轉盤背景和開始按鈕。按鈕的點擊事件里設置開始動畫,在動畫開始的代理方法中讓開始按鈕不響應點...
    全棧的貓南北閱讀 1,642評論 1 3
  • 孤獨 1 外面是陽光明媚,山上的松樹把白云當成了帽子,各種不同的形狀鑲嵌在樹尾。太陽躲在山腳下安靜的池塘里乘涼,閃...
    蒲公英的夢839閱讀 271評論 0 2