博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UIKit 框架之UISegmentedControl
阅读量:5222 次
发布时间:2019-06-14

本文共 3179 字,大约阅读时间需要 10 分钟。

////  ViewController.m//  UISegmentedControl////  Created by City--Online on 15/5/20.//  Copyright (c) 2015年 XQB. All rights reserved.//#import "ViewController.h"@interface ViewController ()@property(nonatomic,strong) UISegmentedControl *segmentedControl;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    _segmentedControl =[[UISegmentedControl alloc]initWithFrame:CGRectMake(10, 100, 200, 50)];    //属性无效//    _segmentedControl.segmentedControlStyle=UISegmentedControlStyleBar;               //点击后是否恢复原样    _segmentedControl.momentary=NO;    //是否根据segment的内容改变segment的宽度    _segmentedControl.apportionsSegmentWidthsByContent=YES;        //插入    [_segmentedControl insertSegmentWithTitle:@"0" atIndex:0 animated:YES];    [_segmentedControl insertSegmentWithTitle:@"1" atIndex:1 animated:YES];    [_segmentedControl insertSegmentWithTitle:@"2" atIndex:2 animated:YES];    //添加时若插入索引已经存在,则已最新的索引为准重新排序 例如下面的    [_segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"1.jpg"] atIndex:0 animated:YES];    [_segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"2.jpg"] atIndex:1 animated:YES];    //删除时也是和插入一样 删除一个之后重新排序    [_segmentedControl removeSegmentAtIndex:0 animated:YES];    [_segmentedControl removeSegmentAtIndex:0 animated:YES];    //删除所有的块//    [_segmentedControl removeAllSegments];        //标题    [_segmentedControl setTitle:@"001" forSegmentAtIndex:0];    NSString *titleIndex2=[_segmentedControl titleForSegmentAtIndex:2];    NSLog(@"title=%@",titleIndex2);        //图片    [_segmentedControl setImage:[UIImage imageNamed:@"1.jpg"] forSegmentAtIndex:1];    UIImage *imgIndex1=[_segmentedControl imageForSegmentAtIndex:1];    NSLog(@"UIImage=%@",imgIndex1);        //宽度    [_segmentedControl setWidth:30 forSegmentAtIndex:2];    //如果未设置则获取的为0    float widthIndex1=[_segmentedControl widthForSegmentAtIndex:2];    NSLog(@"width=%lf",widthIndex1);        //内容偏移量    [_segmentedControl setContentOffset:CGSizeMake(5, 5) forSegmentAtIndex:0];    CGSize size=[_segmentedControl contentOffsetForSegmentAtIndex:2];    NSLog(@"contentOffset=%@",NSStringFromCGSize(size));        //可用性    [_segmentedControl setEnabled:NO forSegmentAtIndex:0];    BOOL enable=[_segmentedControl isEnabledForSegmentAtIndex:0];    NSLog(@"%d",enable);        //选中的索引值    _segmentedControl.selectedSegmentIndex=2;        //设置segmented的颜色    _segmentedControl.tintColor=[UIColor redColor];    //设置文本样式    NSDictionary *dic=@{NSFontAttributeName:[UIFont systemFontOfSize:20],NSStrikethroughStyleAttributeName:@1};    [_segmentedControl setTitleTextAttributes:dic forState:UIControlStateNormal];        //获取分段控件的个数   NSInteger count= [_segmentedControl numberOfSegments];    NSLog(@"numberOfSegments=%ld",count);        [_segmentedControl addTarget:self action:@selector(valueChanged) forControlEvents:UIControlEventValueChanged];    [self.view addSubview:_segmentedControl];    }-(void)valueChanged{    NSLog(@"selectedIndex=%ld",_segmentedControl.selectedSegmentIndex);}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end

 

转载于:https://www.cnblogs.com/5ishare/p/4516909.html

你可能感兴趣的文章
JQuery 学习
查看>>
session token两种登陆方式
查看>>
IntelliJ IDEA 12集成Tomcat 运行Web项目
查看>>
android smack MultiUserChat.getHostedRooms( NullPointerException)
查看>>
实用的VMware虚拟机使用技巧十一例
查看>>
监控工具之---Prometheus 安装详解(三)
查看>>
不错的MVC文章
查看>>
网络管理相关函数
查看>>
IOS Google语音识别更新啦!!!
查看>>
20190422 T-SQL 触发器
查看>>
[置顶] Linux终端中使用上一命令减少键盘输入
查看>>
poj1422_有向图最小路径覆盖数
查看>>
BootScrap
查看>>
[大牛翻译系列]Hadoop(16)MapReduce 性能调优:优化数据序列化
查看>>
WEB_点击一百万次
查看>>
CodeForces - 878A Short Program(位运算)
查看>>
路冉的JavaScript学习笔记-2015年1月23日
查看>>
Mysql出现(10061)错误提示的暴力解决办法
查看>>
2018-2019-2 网络对抗技术 20165202 Exp3 免杀原理与实践
查看>>
NPM慢怎么办 - nrm切换资源镜像
查看>>