您的位置:首页 > 其它

XCode5 使用AutoLayout情况下改变控件的 方法

2014-01-15 10:32 309 查看
[self.viewButtonsetTranslatesAutoresizingMaskIntoConstraints:NO];

//[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.viewButton attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];

//改变 高度

[self.viewaddConstraint:[NSLayoutConstraint

constraintWithItem:self.viewButton

attribute:NSLayoutAttributeHeight

relatedBy:NSLayoutRelationEqual

toItem:self.view

attribute:NSLayoutAttributeHeight

multiplier:0.3

constant:0]];

[self.viewButtonaddObserver:selfforKeyPath:@"bounds"options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitialcontext:nil];//注册kvo监听bounds的变化

}

//kvo回调

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context

{

if (object == self.viewButton && [keyPath isEqualToString:@"bounds"])

{

// [self.viewButton setTitle:NSStringFromCGSize(self.viewButton.bounds.size) forState:UIControlStateNormal];

NSLog(@"");

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐