基础小控件

/***************************************UIlabel*************************************/

UILabel *label = [[UILabel alloc]init];//创建UIlabel对象

label.frame = CGRectMake(50, 50, 100, 50);//设定label的位置与大小

label.backgroundColor = [UIColoryellowColor];//设定label的背景颜色

label.text = @"123";//给label添加文本

label.tag = 1;//设置label标签,便于以后使用

label.textAlignment = NSTextAlignmentRight;//设置文本对齐方式,系统默认为字体居右

label.textColor = [UIColorblackColor];//设置字体的颜色

label.numberOfLines = 0;//设置文本的行数,0代表有无线行

[label.layersetCornerRadius:10.0];//设置label边框角为圆角,后面数值为圆角的半径

label.font = [UIFontsystemFontOfSize:15];//设置字体的大小

label.adjustsFontSizeToFitWidth = YES;//设置字体大小根据label的大小自动调整

[self.view addSubview:label];//显示label

/***************************************UIlabel*************************************/

/****************************************UISwitch***********************************/

UISwitch *sw = [[UISwitchalloc]init];

sw.frame = CGRectMake(150, 150, 100, 100);//设置位置和大小,发现大小无效。即开关控件大小不受影响

sw.on = YES;//设置开关的状态(开/关)

sw.onImage=[UIImageimageNamed:@"1.png"];//无效

sw.offImage=[UIImageimageNamed:@"logo.png"];//无效,即UISwitch上不能添加图片

[sw addTarget:selfaction:@selector(loop) forControlEvents:UIControlEventValueChanged];//绑定监听方法

[self.view addSubview:sw];//显示sw

/****************************************UISwitch***********************************/

/***************************************UISegmentControl****************************/

UISegmentedControl *seg = [[UISegmentedControlalloc]initWithItems:@[@"",@"",@""]];//初始化seg,并且给seg分段

seg.frame = CGRectMake(50, 200, 200, 50);//设置seg的位置与大小

seg.backgroundColor = [UIColorwhiteColor];//设置seg的背景颜色

[seg setTitle:@"登录"forSegmentAtIndex:0];//给莫一段设置标题

//[seg setImage:[UIImage imageNamed:@"lun"] forSegmentAtIndex:1];//必须添加背景为透明的图片

[seg insertSegmentWithTitle:@"2"atIndex:1animated:YES];//在原有的基础上添加一段,可以设置该段所放的位置与标题

unsigned long int  i = seg.numberOfSegments;//获得seg的总段数

NSLog(@"段数%zi",i);

NSString *s = [seg titleForSegmentAtIndex:2];//获得某一段的标题

NSLog(@"标题%@",s);

UIImage *image = [seg imageForSegmentAtIndex:1];//获得某一段的图片

NSLog(@"图片%@",image);

[seg setWidth:60forSegmentAtIndex:1];//设置某一段的宽度

[seg setEnabled:NO];//激活seg

[seg setEnabled:NOforSegmentAtIndex:2];//激活某一段,yes为激活

seg.selectedSegmentIndex = 2;//设置默认选中项

[seg setBackgroundImage:[UIImageimageNamed:@"lun"] forState:UIControlStateNormalbarMetrics:UIBarMetricsDefault];

[seg addTarget:selfaction:@selector(loop1:) forControlEvents:UIControlEventTouchUpInside];//seg的监听事件

[self.view addSubview:seg];

/***************************************UISegmentControl****************************/

/***************************************UIAlertView********************************/

UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"是否注册"delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:@"取消", nil];

[alert show];

/***************************************UIAlertView********************************/

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

NSLog(@"%ld",(long)buttonIndex);

}//UIAlertView的监听事件

UILabel UISwitch UISegmentedControl UIAlertView的更多相关文章

  1. ios 延迟调用 && UIImageView && UILabel && UISegmentedControl && UISwitch && UISlider

    // //  ViewController.m //  UI_Lesson3 // //  Created by archerzz on 15/8/13. //  Copyright (c) 2015 ...

  2. 【IOS 开发】基本 UI 控件详解 (UISegmentedControl | UIImageView | UIProgressView | UISlider | UIAlertView )

    转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/50163725 一. 分段控件 (UISegmentedControl) 控件展 ...

  3. UI中一些不常用的控件UIActivityIndicatorView、UIProgressView、UISegmentedControl、UIStepper、UISwitch、UITextView、UIAlertController

    //UIActivityIndicatorView //小菊花,加载 #import "ActivityIndicatorVC.h" @interface ActivityIndi ...

  4. UISwitch(开关控件)、UISegmentedControl(分段控件)

    一.UISwitch 1.初始化 UISwitch *s1 = [[UISwitch alloc]initWithFrame:CGRectMake(50, 170, 100, 200)];   2.设 ...

  5. swift系统学习控件篇:UIbutton+UIlabel+UITextField+UISwitch+UISlider

    工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UIButton+UILabel // // ViewController.swift // ...

  6. UI-不常用控件 UIActivityIndicatorView、UIProgressView、UISegmentedControl、UIStepper、UISwitch、UITextView、UIAlertController

    1 //UIActivityIndicatorView //小菊花,加载================================================================ ...

  7. iphone:自定义UIAlertView

    由于项目中有这样一个需求:需要在保存是弹出框选择保存的地点.选择UIAlertView来实现,但是要在UIAlertView中增加UISwitch的控件,这就需要自定义一个继承UIAlertView的 ...

  8. ##DAY2 UILabel、UITextField、UIButton、UIImageView、UISlider

    ##DAY2 UILabel.UITextField.UIButton.UIImageView.UISlider #pragma mark ———————UILabel——————————— UILa ...

  9. 自定义一个类似UIAlertView的弹出框

    这个是和UIAlertView类似,但是可以自定义view的样式废话不多说,上代码: 首先第一步:创建一个继承自View的类如: #import <UIKit/UIKit.h> @clas ...

随机推荐

  1. error_reporting()

    定义和用法 error_reporting() 设置 PHP 的报错级别并返回当前级别. 语法 error_reporting(report_level) 如果参数 level 未指定,当前报错级别将 ...

  2. $(document).ready()和window.onload的区别

    来源于: The window.onload event fires when a document is completely downloaded to the browser. This mea ...

  3. Learning jQuery, 4th Edition 勘误表

    来源于:http://book.learningjquery.com/3145/errata/ Chapter 1 page 14 The CSS snippet is correct, but it ...

  4. model 的验证

    Ext.onReady(function(){ Ext.define('User', { extend: 'Ext.data.Model', fields: [ { name: 'name', typ ...

  5. iOS开发--换肤简单实现以及工具类的抽取

    一.根据美工提供的图片,可以有两种换肤的方案. <1>美工提供图片的类型一: <2>美工提供图片的类型二:这种分了文件夹文件名都一样的情况,拖入项目后最后用真实文件夹(蓝色文件 ...

  6. 使用kuernetes提供高可用的kibana服务

    在kubernetes集群中部署kibana步骤如下: 1:kibana安装文件(目前最新版本4.5.1): 2:编写Dockerfile及执行点脚本文件run.sh,制作Kibana镜像: 3:推送 ...

  7. eclipse-插件安装的三种方式

    (前两种安装方式以多国语言包的安装为例) 1.  普通安装:用直接解压的安装方式来实现 解压插件到某个文件夹 将下载的插件文件解压到 Eclipse 的安装目录下 如插件文件为多国语言包: NLpac ...

  8. js 打开窗口window.open

    js改变原有的地址 window.open(webPath+'/index?code='+code,'_self');

  9. 在MAC上搭建tomcat,再使用servlet时遇到的问题。

    说起来真是惭愧.在mac上配置tomcat环境时.tomcat6能正确运行.但是7,8都运行不了.具体表现是tomcat6访问127.0.0.1:8080可以显示那个界面,然而tomcat7和8都显示 ...

  10. php验证登录

    <html><head> <title></title> <meta charset="utf-8"></head ...