iOS开发中需要注意点的知识点

来源:互联网 发布:钩针图解制作软件 编辑:程序博客网 时间:2024/06/05 20:01
  1. 一般布局子视图的坐标的时候不要在viewDidLoad中做,一般在viewDidLayoutSubviews中布局
- (void)viewDidLayoutSubviews{   [super viewDidLayoutSubviews];   // 布局   xxxView.frame = CGRectMake(x, y, width, height);   xx2View.frame = CGRectMake(x, y, width, height);}
  1. XIB中使用动画和纯代码有些不同,纯代码方式一般都是将动画代码放入到动画代码块中即可,xib方式正好相反:将动画代码放到外边,在动画代码块中调用layoutIfNeeded方法
self.loginRegisterViewLeading.constant = self.loginRegisterViewLeading.constant == 0 ? -self.loginRegisterContainerView.width * 0.5 : 0;[UIView animateWithDuration:0.2 animations:^{    [self.view layoutIfNeeded];}];
  1. 调整UIButton的图片和标题的位置,只需要自定义按钮并重写layoutSubviews即可
// 图上标题下布局- (void)layoutSubviews {    [super layoutSubviews];    // 设置图片坐标    self.imageView.top = 0;    self.imageView.centerX = self.width * 0.5;    // 设置标题坐标    self.titleLabel.top = self.height - self.titleLabel.height;    [self.titleLabel sizeToFit];    self.titleLabel.centerX = self.width * 0.5;}
  1. 改变UITextField的编辑模式下改变光标的颜色,和提示字体的颜色
- (void)awakeFromNib{   self.tintColor = [UIColor whiteColor];   [self addTarget:self action:@selector(textFieldBegin) forControlEvents:UIControlEventEditingDidBegin];}- (void)textFieldBegin{   self.attributePlaceholder = [[NSAttributedString alloc] initWithString:self.placeholder attributes:attrs];}
0 0