Tag: 约束以

如何以编程方式更改显示旋转的布局约束

对于一个应用程序(iOS 7兼容),我需要在横向和纵向模式下完全不同的布局的可能性。 我看到以编程方式设置约束的唯一方法,并在旋转时更改它们。 所以我使用IB设置我的接口,然后以编程方式设置约束。 我看到了某种地方首先删除所有约束的方法,然后创build并添加新的约束,然后为父视图上的约束设置更新标志。 我想要的元素只是整个屏幕的宽度和一个在另一个之下: – (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { self.landscapeConstraints = [NSMutableArray new]; self.portraitConstraints = self.view.constraints; //creation of the viewsDictionary [self.landscapeConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[segmentedControl]-|" options:0 metrics:nil views:viewsDictionary]]; [self.landscapeConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[fullText]-|" options:0 metrics:nil views:viewsDictionary]]; [self.landscapeConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[bubbleTitle]-|" options:0 metrics:nil views:viewsDictionary]]; [self.landscapeConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[bubble]-|" options:0 metrics:nil views:viewsDictionary]]; [self.landscapeConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[chartView]-|" options:0 metrics:nil views:viewsDictionary]]; [self.landscapeConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(20)-[segmentedControl]-[fullText]-[bubbleTitle]-[bubble]-[chartView]|" options:0 […]

更改每个实例的UITableViewCell宽度约束的常量值

我正在尝试创build一个聊天应用程序,在那里我只使用代码做了一个自定义的UITableViewCell。 所以就像泡泡里面的名字,消息和时间标签一样, 名称标签应该是总气泡宽度的一半,气泡宽度由最大宽度为220.0f的消息的宽度决定,之后它将转到下一行。 我面临的问题是:我试图根据消息宽度更改名称标签的宽度约束的常量。 但是由于iOS重用了这个单元格,当我滚动我的UITableView的时候,一些名称标签的宽度会变得混乱。 它试图使用旧的宽度,因此,如果名称足够大,名称标签将从泡泡中跳出。 我附上一些图像来certificate: 正确的名称标签宽度http://postimg.org/image/yd6z2jdft/c1f192cd/ 名称标签由于滚动而产生错误的宽度http://postimg.org/image/u0m7pc8uh/cd7ea4ea/ 这是我正在使用的代码。 我只发布相关部分 的cellForRowAtIndexPath: chatCell = (ChatTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"chatSend"]; if (chatCell == nil) { chatCell = [[ChatTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"chatSend"]; } chatCell.chatMessageLabel.text = message.getMessage; chatCell.chatNameLabel.text = message.getFromName; chatCell.chatTimeLabel.text = [dateFormatter stringFromDate:messageDateTime]; [chatCell setChatNameLabelWidth:Messagesize.width]; Heightforrowatindexpath: Messagesize = [message.getMessage boundingRectWithSize:CGSizeMake(220.0f, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:14]} context:nil].size; ChatTableViewCell.m 在课堂延伸 @property (nonatomic, […]