开发者

Possible UITableViewCell UILabel Compositing Anomaly

开发者 https://www.devze.com 2023-02-15 22:26 出处:网络
Consider a UITableViewCell with a style of UITableViewCellStyleDefault, set in tableView:cellForRowAtIndexPath:, and a gradient background, set in tableView:willDisplayCell:forRowAtIndexPath:.

Consider a UITableViewCell with a style of UITableViewCellStyleDefault, set in tableView:cellForRowAtIndexPath:, and a gradient background, set in tableView:willDisplayCell:forRowAtIndexPath:.

When this is rendered, the textLabel will blend in just fine with the gradient, and highlighting works just as well.

Now, what if we keep everything identical, but change the cell style to UITableViewCellStyleSubtitle? In my case, the textLabel and detailTextLabel no longer blend at all! They take on ... some other color. Not too far off from the colors in the gradient, but it simply doesn't blend. Change the style back to default, and all is well.

Now, I realize I could set the labels to clearColor in ...willDisplayCell... but I've been told over and over again, "Don't do that! Leave them colors alone."

Perhaps I have to do that as a workaround? Or might something else 开发者_开发百科be amiss? Clues welcome/appreciated!


A work around would be to use NSString's drawInRect function. You could use the NSString sizeWithFont:forWidth:lineBreakMode: method to calculate the rect size and then draw the strings out that way.

more about string sizes and drawing here on apples docs site.

0

精彩评论

暂无评论...
验证码 换一张
取 消