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(@"");
}
}
//[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(@"");
}
}
相关文章推荐
- 用autolayout如何在横竖屏切换情况下改变控件的位置
- iOS 使用LayoutGuide 来限制控件的位置,配合Auto Layout constraints
- Java代码使用LayoutParams改变RelativeLayout 中的控件布局
- Swing中使用Box(BoxLayout)添加控件间的距离的三种方法
- StoryBoard不使用AutoLayout情况下 按比例快速兼容适配iPhone6/6 Plus教程【原创】
- 【Android动态布局】之【使用addView方法时,如何保持已有动态控件位置不被改变】
- 使用JavaScript脚本无法直接改变Asp.net中Checkbox控件的Enable属性的解决方法
- android侧滑菜单控件DrawerLayout使用方法详解
- ListView使用自定义适配器的情况下实现适配器的控件点击事件执行Activity界面中的方法
- StoryBoard不使用AutoLayout情况下 按比例快速兼容适配iPhone6/6 Plus教程【转载】
- 使用addView方法时,如何保持已有动态控件位置不被改变
- SmartRefreshLayout刷新控件的使用方法 (刷新加载时用GIF动画)
- IOS开发之读取使用AutoLayout约束的控件Frame
- iOS 使用代码实现Autolayout的方法
- 使用addView方法时,保持已有动态控件位置不被改变
- 转,StoryBoard不使用AutoLayout情况下 按比例快速兼容适配iPhone6/6 Plus教程
- Auto Layout: IB和代码结合使用约束,以及约束在UIView动画中的改变
- 常量,字段,构造方法 调试 ms 源代码 一个C#二维码图片识别的Demo 近期ASP.NET问题汇总及对应的解决办法 c# chart控件柱状图,改变柱子宽度 使用C#创建Windows服务 C#服务端判断客户端socket是否已断开的方法 线程 线程池 Task .NET 单元测试的利剑——模拟框架Moq
- Silverlight AutoCompleteBox(自动完成输入框控件)使用方法