UI控件-Segmentarray

来源:未知 责任编辑:智问网络 发表时间:2013-09-26 23:53 点击:
\


用代码创建处Segmentarray控件,并设置它的一些属性:

[cpp] /*segmentarray.h*/ 
 
#import <UIKit/UIKit.h>  
 
@interface segmentarray : UIViewController 

    //创建控件对象  
    UISegmentedControl *segment; 

@property (nonatomic,retain) UISegmentedControl *segment; 
@end 
/*segmentarray.h*/

#import <UIKit/UIKit.h>

@interface segmentarray : UIViewController
{
    //创建控件对象
    UISegmentedControl *segment;
}
@property (nonatomic,retain) UISegmentedControl *segment;
@end

 

 


在  .m  文件中初始化及设置属性值

[cpp] - (void)viewDidLoad 

    [super viewDidLoad]; 
     
    //建立一个数组,来存放title  
    NSArray *Segmentarray = [[NSArray alloc]initWithObjects:@"1",@"2",@"3",@"4",nil]; 
     
    //初始化SegmentControl对象,并把title添加进去  
    self.segment = [[UISegmentedControl alloc]initWithItems:Segmentarray]; 
     
    //使用完后,释放NSArray对象  
    [Segmentarray release]; 
     
    //定位,设置添加到界面中的位置和它的宽/高  
    self.segment.frame = CGRectMake(40, 60, 120, 40); 
     
    //设置控件SegmentControl的风格  
    self.segment.segmentedControlStyle = UISegmentedControlStyleBezeled; 
    /* 四种控件风格
     UISegmentedControlStylePlain,     // large plain
     UISegmentedControlStyleBordered,  // large bordered
     UISegmentedControlStyleBar,       // small button/nav bar style. tintable
     UISegmentedControlStyleBezeled,   // large bezeled style. tintable
     */ 
     
    //设置初始的默认值,根据索引值来设置  
    self.segment.selectedSegmentIndex = 2; 
     
    //把控件添加到view中  
    [self.view addSubview:self.segment]; 
     
    //释放SegmentControl对象  
    [segment release]; 

 

 

摘自 like7xiaoben

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • Lexical or Preprocessor Issue 'xxx.h
    • ios学习笔记(二)xcode 4.3.2下实现基本交互
    • ios版本的helloworld
    • iphone(object-c) 内存管理(3) 有效的内存管理 前半部分
    • ios学习笔记(一)xcode 4.3.2下创建第一个ios项目
    • IOS类似iphone通讯录TableView的完整demo【附源码】
    • UITableView一些方法
    • [iPhone中级]iPhone团购信息客户端的开发 (二)
    • 如何为Iphone应用创建启动界面
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1