UI控件

作者: 乐乐的熊 | 来源:发表于2018-11-09 19:55 被阅读1次

UIButton

1.注意UIbutton的selected的状态;

  1. 设置的这个状态,如果后面改变button的selected的Bool值,则该titleColor就会改变;
  [button setTitleColor:KWhiteColor forState:UIControlStateSelected];
      [button setTitleColor:KBlackColor forState:UIControlStateNormal];

2.自己判断的,如果当selected的bool值改变时,需要在后面添加该代码,才可以变色;因为他不会回去走该代码。

        if(sender.selected) {
            [sender setBackgroundColor:[UIColor colorWithRed:0.16 green:0.48 blue:1.00 alpha:1.00]];
            sender.layer.borderColor = KWhiteColor.CGColor;
        } else {
            [sender setBackgroundColor:KWhiteColor];
            sender.layer.borderColor = KLightTitleColor.CGColor;
        }

3.font
button.titleLabel.font

UITextFiled

1.textFiled的键盘的弹出和收回

   [textf becomeFirstResponder];
    [textf resignFirstResponder];

2.点键盘外收回键盘

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

3.监听键盘的弹出和收回,进而定制键盘
添加观察者

//  添加观察者,监听键盘弹出
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardDidShow:) name:UIKeyboardWillShowNotification object:nil];

    //  添加观察者,监听键盘收起
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardDidHide:) name:UIKeyboardWillHideNotification object:nil];
- (void)keyBoardDidShow:(NSNotification*)notifiction {

    //获取键盘高度
    NSValue *keyboardObject = [[notifiction userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey];
    
    NSLog(@"%@",keyboardObject);
    
    CGRect keyboardRect;
    
    [keyboardObject getValue:&keyboardRect];
    
    //得到键盘的高度
    //CGRect keyboardRect = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue];
    
    // 取得键盘的动画时间,这样可以在视图上移的时候更连贯
    double duration = [[notifiction.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    NSLog(@"%f",duration);
    //调整放置有textView的view的位置
    
    //设置动画
    [UIView beginAnimations:nil context:nil];
    
    //定义动画时间
    [UIView setAnimationDuration:duration];
    [UIView setAnimationDelay:0];
    
    //设置view的frame,往上平移
    [(UIView *)[self.view viewWithTag:1000] setFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height-keyboardRect.size.height-70, [UIScreen mainScreen].bounds.size.width, 70)];
    
    //提交动画
    [UIView commitAnimations];
}
- (void)keyBoardDidHide:(NSNotification*)notification {

    //定义动画
    [UIView beginAnimations:nil context:nil];
     [UIView setAnimationDuration:0.25];
    
    //设置view的frame,往下平移
    [(UIView *)[self.view viewWithTag:1000] setFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - 70, [UIScreen mainScreen].bounds.size.width, 70)];
     [UIView commitAnimations];
}

4 button

使用xib创建btn,当选择btn的状态进行改变时,需要设置btn的type。

5 segmentControl 分段控制器

1 使用
https://www.jianshu.com/p/7d9e4d4368c8
2 和scrollview的联动

5 TextView

修改2个属性 enable 和 selectable

相关文章

  • UI常用控件

    UI常用控件 // // ViewController.m // UI常用控件 // // Created by ...

  • 自用命名规范

    UI命名规范 普通UI命名 控件类型_ui名称 UI绑定脚本命名 控件类型简称_ui绑定脚本名称_bind 文件规...

  • Android理解自定义View

    当Android SDK中提供的系统UI控件无法满足业务需求时,我们就需要考虑自己实现UI控件。 自定义UI控件有...

  • setText的优化

    Android的许多UI控件都有显示文字的功能,如TextView、EditText等UI控件。这些控件都通过se...

  • Android自定义View

    当Android SDK中提供的系统UI控件无法满足业务需求时,就需要考虑自己实现UI控件 自定义UI控件有2种方...

  • iOS资源汇总

    iOS·Objective-C UI控件详解整理 iOS UI控件详解—「UIScrollView滚动视图」 iO...

  • 第一行代码(2)UI设计

    1. 基础UI控件 Android中的基础UI控件有这样几种: TextView Button EditText ...

  • IOS规范,扎实基础(1)

    目录: UI Bars UI Views (用户界面视图) UI Controllers (用户界面控件) UI ...

  • Android为什么不允许在子线程中访问UI

    首先,UI控件不是线程安全的,如果多线程并发访问UI控件可能会出现不可预期的状态那为什么系统不对UI控件的访问加上...

  • 第五章 Android 常见UI基础控件(一)

    这里主要讲讲新的Android 基础的UI控件,此外还拓展下新的控件。所有的控件都是View的子类。常见的UI控件...

网友评论

      本文标题:UI控件

      本文链接:https://www.haomeiwen.com/subject/nutaxqtx.html