iOS UISegmentedControl的例子

來源:互聯網
上載者:User

標籤:

 

#import <UIKit/UIKit.h>

 

@interface ViewController : UIViewController

 

@property(strong,nonatomic) UIImageView *MyImage;

 

@property(strong,nonatomic) UITextView *MyView;

 

@property(strong,nonatomic) UISegmentedControl *MySegment;

 

#import "ViewController.h"

 

@interface ViewController ()

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad

{

    [super viewDidLoad];

    

    self.MyView=[[UITextView alloc] initWithFrame:CGRectMake(60, 500, 300, 200)];

    self.MyView.font=[UIFont systemFontOfSize:18];

    self.MyView.textColor=[UIColor redColor];

    self.MyView.userInteractionEnabled=NO;

    [self.view addSubview:self.MyView];

    //添加 分段標識

    self.MySegment=[[UISegmentedControl alloc] initWithItems:@[@"食肉植物",@"觀花植物",@"木本植物",@"多肉植物"]];

    self.MySegment.frame=CGRectMake(60, 100, 300, 50);

    

    [self.view addSubview:self.MySegment];

    //添加視圖

    self.MyImage=[[UIImageView alloc] initWithFrame:CGRectMake(60, 180, 300,300)];

     [self.view addSubview:self.MyImage];

    

    //添加背景

    self.view.backgroundColor=[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"背景圖.png"]];

    

    //事件

    [self.MySegment addTarget:self action:@selector(ValueChange) forControlEvents:UIControlEventValueChanged];

    

}

/**

 *  觸發事件

 */

-(void)ValueChange

{

 

    switch (self.MySegment.selectedSegmentIndex)

    {

        case 0:

    

            self.MyImage.image=[UIImage imageNamed:@"食肉植物.jpg"];

            [email protected]"食蟲植物是一種會捕獲並消化動物而獲得營養(非能量)的自養型植物。食蟲植物的大部分獵物為昆蟲和節肢動物。其生長於土壤貧瘠,特別是缺少氮素的地區,例如酸性的沼澤和石漠化地區。1875年,查爾斯·達爾文發表了第一篇關於食蟲植物的論文。"; 

        break;

         

        case 1:

            self.MyImage.image=[UIImage imageNamed:@"觀花植物.png"];

            [email protected]"風信子(學名:Hyacinthus orientalis L.):是多年草本球根類植物,鱗莖卵形,有膜質外皮,皮膜顏色與花色成正相關,未開花時形如大蒜,原產地中海沿岸及小亞細亞一帶,是研究發現的會開花的植物中最香的一個品種。";

            break;

            

        case 2:

            self.MyImage.image=[UIImage imageNamed:@"木本植物.png"];

            [email protected]"桃(學名:Amygdalus persica L.):薔薇科、桃屬植物。落葉小喬木;葉為窄橢圓形至披針形,長15厘米,寬4厘米,先端成長而細的尖端,邊緣有細齒,暗綠色有光澤,葉基具有蜜腺。";

            break;

        case 3:

            self.MyImage.image=[UIImage imageNamed:@"多肉植物.png"];

            [email protected]" 仙人球是外形呈球狀的仙人掌科植物的統稱,有很多品種。它們的原生地多為沙漠地帶,喜高溫乾旱氣候。莖呈球形或橢圓形,綠色,花著生於縱棱刺叢中,仙人球開花一般在清晨或傍晚。";

            break;

            default:

            break;

    }

}

 

iOS UISegmentedControl的例子

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.