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

    xiaoxiao2022-06-23  40

    一般布局子视图的坐标的时候不要在viewDidLoad中做,一般在viewDidLayoutSubviews中布局 - (void)viewDidLayoutSubviews{ [super viewDidLayoutSubviews]; // 布局 xxxView.frame = CGRectMake(x, y, width, height); xx2View.frame = CGRectMake(x, y, width, height); } XIB中使用动画和纯代码有些不同,纯代码方式一般都是将动画代码放入到动画代码块中即可,xib方式正好相反:将动画代码放到外边,在动画代码块中调用layoutIfNeeded方法 self.loginRegisterViewLeading.constant = self.loginRegisterViewLeading.constant == 0 ? -self.loginRegisterContainerView.width * 0.5 : 0; [UIView animateWithDuration:0.2 animations:^{ [self.view layoutIfNeeded]; }]; 调整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; } 改变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]; }
    转载请注明原文地址: https://ju.6miu.com/read-1123395.html

    最新回复(0)