0
我在自定義UIView中有一個UILabel
和一個UIButton
。我的UIButton
網站低於我的UILabel
。當UILabel動態調整大小時,在UIView中移動UIButton。 iOS
我的UILabel
文本會改變它的大小並與我的UIButton
重疊。
我想在UILabel調整自己的大小時能夠將UIButton向下移動嗎?
我只能設法動態調整我的UILabel
的大小,但無法調整大小或移動我的UIButton
。
self.chosenCategoriesLabel.font = [UIFont fontWithName:@"Helvetica-Light" size:17.0];
self.chosenCategoriesLabel.textColor = [UIColor colorWithRed:161.0/255.0 green:205.0/255.0 blue:86.0/255.0 alpha:1.0];
self.chosenCategoriesLabel.font = [UIFont fontWithName:@"Helvetica-Light" size:15.0];
self.chosenCategoriesLabel.numberOfLines = 0;
self.selectedCategoriesString = [self.selectedCategoriesArray componentsJoinedByString:@","];
self.chosenCategoriesLabel.lineBreakMode = NSLineBreakByWordWrapping;
self.chosenCategoriesLabel.text = [self.selectedCategoriesString stringByAppendingString:@"\n\n\n\n"];
[self.selectionsWrapper addSubview:self.chosenCategoriesLabel];
self.chosenCategoriesLabel.frame = CGRectMake(self.chosenCategoriesLabel.frame.origin.x, self.chosenCategoriesLabel.frame.origin.y, self.chosenCategoriesLabel.frame.size.width, [self sizeLabel]);
[self.itemThumbnail setImageWithURL:self.item.itemImageURL placeholderImage:[UIImage imageNamed:@"profile-image-placeholder"]];
[self.view addSubview:self.itemThumbnail];
[self.selectCategorieButton setTitle:@"Select Categories" forState:UIControlStateNormal];
[self.selectCategorieButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.selectCategorieButton setTitle:@"Select Categories" forState:UIControlStateHighlighted];
[self.selectCategorieButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
self.selectCategorieButton.titleLabel.font = lightHelveticaFont;
[self.selectCategorieButton setBackgroundImage:[UIImage imageNamed:@"btn_choose_categories.png"] forState:UIControlStateNormal];
[self.selectCategorieButton setBackgroundImage:[UIImage imageNamed:@"btn_choose_categories.png"] forState:UIControlStateHighlighted];
[self.selectCategorieButton.titleLabel setFont:[UIFont boldSystemFontOfSize:15]];
[self.selectCategorieButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Light" size:15.0]];
[self.selectionsWrapper addSubview:self.selectCategorieButton];
[self changeLabel];
self.chosenCategoriesLabel.frame = CGRectMake(self.chosenCategoriesLabel.frame.origin.x, self.chosenCategoriesLabel.frame.origin.y, self.chosenCategoriesLabel.frame.size.width, [self sizeLabel]);
-(void)changeLabel {
self.chosenCategoriesLabel = [NSString stringWithFormat:@"%@",array];
self.chosenCategoriesLabel.frame = CGRectMake(self.chosenCategoriesLabel.frame.origin.x, self.chosenCategoriesLabel.frame.origin.y, self.chosenCategoriesLabel.frame.size.width, [self sizeLabel]);
}
- (CGFloat) sizeLabel
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
CGSize sizeToFit = [self.chosenCategoriesLabel.text sizeWithFont:[UIFont systemFontOfSize:12.0f] constrainedToSize:CGSizeMake(276.0f, CGFLOAT_MAX) lineBreakMode:NSLineBreakByWordWrapping];
#pragma clang diagnostic pop
return fmaxf(22.0f, sizeToFit.height + 40); }
這是你的初始化代碼嗎?你能否展示你調整你的標籤的部分? – streem
你在哪裏創建按鈕和標籤?因爲你似乎通過代碼將它們添加到視圖中? – Flexicoder
我在界面生成器中創建了uibutton和uilabel。我只更改我的代碼 – CapeFurSeal