UIsegment Custom
2013-10-09 14:29
183 查看
84down vote | You need to provide the following images: segment background selected (this has both left and right caps) segment background unselected (this has both left and right caps) segment middle, left selected, right unselected segment middle, left unselected, right selected segment middle, both left & right selected segment middle, both left & right unselected And then use the following code to set: /* Unselected background */ UIImage *unselectedBackgroundImage = [[UIImage imageNamed:@"segment_background_unselected"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)]; [[UISegmentedControl appearance] setBackgroundImage:unselectedBackgroundImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; /* Selected background */ UIImage *selectedBackgroundImage = [[UIImage imageNamed:@"segment_background_selected"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)]; [[UISegmentedControl appearance] setBackgroundImage:selectedBackgroundImage forState:UIControlStateSelected barMetrics:UIBarMetricsDefault]; /* Image between two unselected segments */ UIImage *bothUnselectedImage = [[UIImage imageNamed:@"segment_middle_unselected"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 0, 15, 0)]; [[UISegmentedControl appearance] setDividerImage:bothUnselectedImage forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; /* Image between segment selected on the left and unselected on the right */ UIImage *leftSelectedImage = [[UIImage imageNamed:@"segment_middle_left_selected"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 0, 15, 0)]; [[UISegmentedControl appearance] setDividerImage:leftSelectedImage forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; /* Image between segment selected on the right and unselected on the left */ UIImage *rightSelectedImage = [[UIImage imageNamed:@"segment_middle_right_selected"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 0, 15, 0)]; [[UISegmentedControl appearance] setDividerImage:rightSelectedImage forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault]; Note that you'll have to adjust the cap size in the stretchable images to match your images. |
相关文章推荐
- android custom viewgroups 性能分析
- (译)Getting Started——1.3.4 Writing a Custom Class(编写自定义的类)
- [UGUI]UGUI使用图片文字(Custom Font)
- web_custom_request
- spring读取资源文件时自定义数据类型转换---CustomEditorConfigurer
- Android翻页效果原理实现之曲线的实现 分类: Custom My Love
- web_custom_request函数之Body详解
- IOS_UI_ImageView Image 手势 UISwitch UISegmentControl
- Error creating bean with name 'org.apache.cxf.binding.soap.customEditorConfigurer'
- Custom view … overrides onTouchEvent but not performClick
- ApiDemos—FragmentCustomAnimations分析
- Android 如何在自定义界面上启用输入法 (How to enable inputmethod for the custom UI)
- 有关custom container of view controllers
- Unity的UGUI中使用CustomFont(BMFont)
- Folding Custom Regions with Line Comments -- 解决idea中代码收起的问题
- WWDC 2012 Session笔记——219 Advanced Collection Views and Building Custom Layouts
- custom WCF data service
- CustomViewAccessibilityActivity
- Part 13 Create a custom filter in AngularJS
- tomcat server for the webapp can be custom defined.