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];

  • 相关阅读:
    BZOJ 1013--[JSOI2008]球形空间产生器sphere(高斯消元)
    BZOJ 1012--[JSOI2008]最大数maxnumber(二分&单调栈)
    BZOJ 3357--[Usaco2004]等差数列(STL&DP)
    BZOJ 1011--[HNOI2008]遥远的行星(乱搞)
    BZOJ 1010--[HNOI2008]玩具装箱toy(斜率优化dp)
    BZOJ 5334--[Tjoi2018]数学计算(线段树)
    BZOJ 5395--[Ynoi2016]谁的梦(STL&容斥)
    BZOJ 1008--[HNOI2008]越狱(容斥&快速幂)
    一个典型的装饰器
    Nginx 配置文件详解
  • 原文地址:https://www.cnblogs.com/zhaochaobin/p/5259981.html
Copyright © 2011-2022 走看看