开发者

Changing UITableCellView appearance before it is highlighted (from UITableView)

开发者 https://www.devze.com 2023-02-06 13:21 出处:网络
I may have taken a million wrong turns to get to this question, so I\'m happy to revise if someone can spot where I went wrong.

I may have taken a million wrong turns to get to this question, so I'm happy to revise if someone can spot where I went wrong.

I am trying to build a tableview that looks the same as the Contacts app. My first issue is that an entry will have both a bolded and unbolded string in a given row like "John Appleseed" or "Martin Luther King". I figured I need have two UILabels within my UITableViewCell (possible my first mistake).

A开发者_运维知识库ll I want to do is simply add that second UILabel so instead of subclassing I just add another UILabel in UITableViewCell (possible my next mistake).

However when a row is highlighted (but not yet selected) the default UILabel text switches to white, but my ad-hoc UILabel remains black. I can only force the UILabel text to change to white in the UITableViewDelegate methods which occur AFTER the highlighting. This cause I noticeable flash of white -> black.

Now I see the UITableViewCell method 'setHighlighted:animated:' which I could override if I subclassed, but I was hoping the were another way to approach it.

Thoughts?


I think you're going to find it difficult to keep the last name proportionally spaced from the other portion of the name in a separate view, especially given that the views may be resized by the table view in a number of situations (for example, to accommodate controls when the table view is in editing mode).

It should be a lot easier to create a custom subclass of UITableViewCell and override its -drawRect: method to draw the text itself. Take a look at the UIStringDrawing category on NSString for a list of messages you can send to an instance of NSString to tell it to draw itself either at a given point, or within a given rectangle.

0

精彩评论

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