开发者

How can I get the frame positions of subviews in Apple's UITableView styles?

开发者 https://www.devze.com 2023-02-15 04:45 出处:网络
I\'m trying to make a cell that looks just like Apple\'s UITableViewCellStyleSubtitle, except the textLabel is a UITextView (so it can be edited). I just se开发者_高级运维t the textLabel to \" \" (so

I'm trying to make a cell that looks just like Apple's UITableViewCellStyleSubtitle, except the textLabel is a UITextView (so it can be edited). I just se开发者_高级运维t the textLabel to " " (so that the detailTextView is in the right place) and park a UITextView on top of it. So far, so good. It's working except that I can't quite get my UITextView to line up with the other textLabels of the other cells. I'm a tad off (in more ways than one...).

So that got me wondering: is there a way to get the frame of the various bits of a UITableViewCellStyleSubtitle cell? The obvious (or seemingly-obvious) way does't work. cell.textLabel.frame returns nil, and if you print it, it shows (0, 0, 0, 0) for its frame. Maybe there's another way.

I realize I could hardcode it, but I'm still guessing what those dimensions might be. Programmatically would be nicer... I think.

Thoughts?

Thanks,

Bill


A view's frame isn't valid if the view's transform is not the identity transform. I haven't tried it, but you might be able to duplicate the positions of the elements this way:

  1. store the cell's transform
  2. set the cell's transform to CGAffineTransformIdentity
  3. get the frames of the elements
  4. set your own elements with the same frames
  5. apply the original transform to your cell

It'd be interesting to know if that works -- please post back if you have good luck.

0

精彩评论

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