溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

IOS學習筆記(七)之UISegmentedControl分段控件的基本概念和使用方法

發(fā)布時間:2020-09-24 05:21:22 來源:網絡 閱讀:548 作者:jiangqq900826 欄目:移動開發(fā)

     IOS學習筆記(七)之UISegmentedControl分段控件的基本概念和使用方法

     Author:hmjiangqq

     Email:jiangqqlmj@163.com

UISegmentedControl

首先看下官網介紹:

IOS學習筆記(七)之UISegmentedControl分段控件的基本概念和使用方法

 A UISegmentedControl object is a horizontal control made of multiple segments, each segment functioning as a discrete button. A segmented control affords   a compact means to group together a number of controls.

 A segmented control can display a title (an NSString object)   or an p_w_picpath (UIImage object).   The UISegmentedControl object automatically resizes segments to fit proportionally within their superview unless they have a specific width set. When   you add and remove segments, you can request that the action be animated with sliding and fading effects.

分段控件是一種選擇控件,功能有點類似于Windows中的單選按鈕,由兩端或者更多段組成,


每個段相當于一個獨立的按鈕。這控件一般有兩種樣式-Plain&Bordered樣式和Bar樣式,

Bordered樣式是在Plain樣式上面加上了一個邊框.Plain和Bordered樣式中每一段都可以設置文本

和添加圖片.Bar樣式整體來說比較窄,在其中我們一般不會放置圖片。

常用的屬性和方法如下:

IOS學習筆記(七)之UISegmentedControl分段控件的基本概念和使用方法IOS學習筆記(七)之UISegmentedControl分段控件的基本概念和使用方法

實例代碼如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];     // Override point for customization after application launch.     self.window.backgroundColor = [UIColor whiteColor];          NSArray *array=@[@"搜索",@"選擇",@"視頻",@"圖片"];     UISegmentedControl *segmentControl=[[UISegmentedControl alloc]initWithItems:array];     segmentControl.segmentedControlStyle=UISegmentedControlStyleBordered;     //設置位置 大小     segmentControl.frame=CGRectMake(60, 100, 200, 40);     //默認選擇     segmentControl.selectedSegmentIndex=1;     //設置背景色     segmentControl.tintColor=[UIColor greenColor];     //設置監(jiān)聽事件     [segmentControl addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];     [self.window addSubview:segmentControl];     [segmentControl release];          [self.window makeKeyAndVisible];     return YES; }  -(void)change:(UISegmentedControl *)segmentControl{     NSLog(@"segmentControl %d",segmentControl.selectedSegmentIndex); }

運行截圖:  


IOS學習筆記(七)之UISegmentedControl分段控件的基本概念和使用方法

IOS學習筆記(七)之UISegmentedControl分段控件的基本概念和使用方法

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。

AI