基础控件整理(持续更新…)

时间:2021-7-21 作者:qvyue

UIView

//移除view中所有的字视图
[self.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

//设置阴影(颜色,偏移坐标,透明度)
view.layer.shadowColor=[UIColor grayColor].CGColor;
view.layer.shadowOffset=CGSizeMake(-1, -2);
view.layer.shadowOpacity=0.2;

UIImageView

//等比拉伸
imgView.contentMode =UIViewContentModeScaleAspectFill;
//裁掉多余部分
imgView.clipsToBounds = YES;

UITextField

//缩回键盘
 [[[UIApplication sharedApplication]keyWindow]endEditing:YES];
//为某个控件调起(缩回)键盘
[self.textField becomeFirstResponder];
[self.textField resignFirstResponder];
//textfield输入时显示系统默认键盘,加载自定义键盘是替换nil即可
self.textField.inputView=nil;
[self.textField reloadInputViews];
//删除最后一位字符
[self.textField deleteBackward];
//设置文本的左边距
UIView *view = [UIView new];
view.frame = CGRectMake(0 ,0 ,width ,0);
textField.leftView = view
textField.leftViewMode = .always
//修改textfield的提示字符颜色
-(NSAttributedString *)chageTextfieldPlacColor:(NSString *)plachorStr andPlacTextColor:(UIColor *)color{
    NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:plachorStr attributes:@{NSForegroundColorAttributeName:color}];
    return attrString;
}
声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:qvyue@qq.com 进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。