开发者

change UIbutton color inside UITableViewCell

I have a simple problem ... but its turning into a very difficult problem .. i have a button inside uitableviewcell and want to change its color through code .... i could aceive it by changing its background image. 开发者_JAVA技巧But its kinna hazy ... its not the solid color ... and when i use [cell.button setBackgroundColor:[UIcolor redColor]] ... the button color does not change ...

any help appreciated

thanks


I am not sure about how are you doing this, but if it is possible, why don't you keep reference to this button.

You can initialize it, insert it on your table and all the time that you need to change something, you use the variable that you have initialized.


// On your .h
UIButton *myButton;

// On your .m
// Initialize it.


// when displaying cells
cell.button = myButton;


// when you need to change the color use your myButton reference
myButton.backgroundColor = ...... 

Cheers,
VFN


If you have a background image (correct me if I got it wrong) then there is no chance to change the background color (or, at least, see this change) without changing the background image...

If you don't have a BG image then it should work...

Where do you change the color?
Inside the tableView:cellForRowAtIndexPath: or do you have a reference to the button?

UPDATE:

Haven't noticed the [cell.button.
What is cell?


Actually changing the background color would change the corners of the button slightly but you may not notice it as rounded rect button just blocks its background as long as it is not transparent.

I believe what you want to do is to change the tint color.

try

 [cell.button setTintColor:[UIcolor redColor]];

I guess it should work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜