UI控件-Segmentarray
用代码创建处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
相关新闻>>
- 发表评论
-
- 最新评论 更多>>