开发者

How can I Get textcolors from controls and assign them to a variable for later use?

I've set colors for my controls in interface builder.

开发者_开发技巧

I need to dump these colors and assign them to variables.

I then want to use these variable for other controls.

Can someone point me at an example ?


The way you programmatically access one of the color properties of your control, actually depends on the control itself, and the color you want. But here is an example using UIButton storing its currentTitleColor property (UIColor).

// accessing the currentTitleColor of button1
// and storing in button1CurrentTitleColor
UIColor *button1CurrentTitleColor = [button1 currentTitleColor];
// or UIColor *button1CurrentTitleColor = button1.currentTitleColor;
// then assigning to a second button
[button2 setCurrentTitleColor:button1CurrentTitleColor];

That said, unless you really need to reuse the color, you can shortcut it like so :

[button2 setCurrentTitleColor:button1.currentTitleColor];

You can find the list of properties for each control class in their respective documentation pages. Hope that helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜