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

來源:互聯網
上載者:User

IOS學習筆記(七)之UISegmentedControl分段控制項的基本概念和使用方法(部落格地址:http://blog.csdn.net/developer_jiangqq)

Author:hmjiangqq

Email:jiangqqlmj@163.com

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 image (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樣式整體來說比較窄,在其中我們一般不會放置圖片。

常用的屬性和方法如下:


執行個體代碼如下:

- (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];    //設定監聽事件    [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);}
運行:



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.