我試圖在UITableViewCell的imageView內放置各種尺寸的圖像。我同步獲取圖像數據,創建圖像,設置imageView的內容模式,最後設置imageView的邊界。但代碼似乎對我所做的任何更改都不敏感。我希望圖像以75x75的區域爲中心。我爲此寫了下面的代碼更改imageView的UITableViewCell的邊界
UIImage* image = [UIImage imageWithData:data];
[holder.imageView setContentMode:UIViewContentModeCenter || UIViewContentModeRedraw];
[holder.imageView setImage:image];
[holder.imageView setBounds:CGRectMake(0,0,75,75)];
[holder.imageView setFrame:CGRectMake(0,0,75,75)];
[holder setNeedsLayout];
其中holder是UITableViewCell。我得到的結果總是一樣的。所有圖片都有75px的高度和不同的寬度。有人可以幫我解決這個問題嗎?
我已經意識到設置contentMode和bounds屬性在該代碼中沒有任何影響。我已經在最後一行後添加一個NSLog的,並得到結果如下:
NSLog(@"imageview:%@ bounds and contentMode:%@ %@",[holder imageView],[holder.imageView bounds],[holder.imageView contentMode]);
imageview的:<的UIImageView:0x39ab8a0; frame =(0 0; 75 75); opaque = NO; userInteractionEnabled = NO;層= <的CALayer:0x39a92b0 >>邊界和 contentMode:(空)(空)
仍然沒有解決
Bummer,我想我可能會被迫創建另一個UITableViewCell子類...感謝您爲我確認它! – 2012-10-04 22:13:01
我必須同意,這是一個巨大的浪費時間,以使其按預期工作。 – 2013-08-16 12:51:44
雖然這個工作,它仍然是一個黑客。人們會期望從自定義UITableViewCell中設置的約束中找出框架/邊界。 – 2014-04-12 20:15:20