zoukankan      html  css  js  c++  java
  • iOS的一些基本控件的使用

    1、UITextField的使用

       //初始化

        self.txtName=[[UITextField alloc] initWithFrame:CGRectMake(100, 20, 200, 50)];

        //添加背景颜色

        self.txtName.backgroundColor=[UIColor redColor];

        //文本框的边框线型

        self.txtName.borderStyle=UITextBorderStyleLine;

        //编辑文本框的提示,在键盘中输入文字时,“请输入姓名”会自动消失

        self.txtName.placeholder=@"请输入姓名";

        //把txtName添加到view上

        [self.view addSubview:self.txtName];

        //手动编辑文本框

        self.txtName.text=@"123456";

        //设置文本框字体的颜色

        self.txtName.textColor=[UIColor purpleColor];

         //设置整体字体背景颜色

        NSMutableAttributedString *str=[[NSMutableAttributedString alloc] initWithString:@"lamco" attributes:@{NSBackgroundColorAttributeName:[UIColor redColor]}];

        

        [str addAttributes:@{NSBackgroundColorAttributeName:[UIColor grayColor]}range:NSMakeRange(2, 3)] ;

        [str addAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} range:NSMakeRange(0, 3)];

        self.txtName.attributedText=str;

        

        self.txtName.returnKeyType=UIReturnKeySearch;

        self.txtName.keyboardType=UIKeyboardTypePhonePad;

    2.键盘的隐藏于弹出方法

    -(BOOL)textFieldShouldReturn:(UITextField *)textField

    {

        if ([textField isFirstResponder]) {

            [textField resignFirstResponder];

        }

        return YES;

    }

    3.UISegmentedControl的使用

    //设置Segment的显示项

        self.mySegment=[[UISegmentedControl alloc] initWithItems:@[@"red",@"green",@"blue"]];

        //设置默认选中项

        self.mySegment.selectedSegmentIndex=1;

        //添加项

        [self.mySegment insertSegmentWithTitle:@"yellow" atIndex:3 animated:YES];

        //设置位置

        self.mySegment.frame=CGRectMake(100, 100, 200, 30);

        //把mySegment添加到父视图view中

        [self.view addSubview:self.mySegment];

       4.UIStepper的使用    

             self.myStepper=[[UIStepper alloc] initWithFrame:CGRectMake(100, 200, 100, 100)];

        //设置最小值

        self.myStepper.minimumValue=1.0;

        //设置最大值

        self.myStepper.maximumValue=10.0;

        //设置每次所加的数

        self.myStepper.stepValue=1.0;

        //前景色

        self.myStepper.tintColor=[UIColor redColor];

        //设置循环

        self.myStepper.wraps=YES;

        [self.view addSubview:self.myStepper];

  • 相关阅读:
    我为什么写博客
    Jquery选中行实现行中的Checkbox的选中与取消选中
    jquery中attr和prop的区别
    如何将.il、.res文件封装成dll文件
    修改VS2010生成的dll文件中的内容
    asp.net mvc4中自定义404页面
    asp.net EF6.0中出现未找到具有固定名称“System.Data.SqlClient”的 ADO.NET提供程序的实体框架提供程序解决办法
    ASP.NET中JSON的序列化和反序列化(转)
     WPF 控件总结
    C语言基础:二维数组 分类: iOS学习 c语言基础 2015-06-10 21:42 16人阅读 评论(0) 收藏
  • 原文地址:https://www.cnblogs.com/zhaochaobin/p/5259981.html
Copyright © 2011-2022 走看看