简体   繁体   中英

Is there something similar to Android's XML Drawables in iOS?

I'm currently creating a "design language" for my company which includes custom drawables for buttons, sliders, etc. Basically the idea is that I want our apps on Android and iOS to look and feel as similar as possible.

I started on Android and created XML drawables for buttons with simple borders and rounded corners, etc. Because I'm using XML, I can easily change things like the line thickness, radius dimension, and color with a single change. Other files reference things like @dimen/default_thickness, etc.

Is there any kind of similar concept on iOS? What I'd like to do is recreate these UI elements on iOS "dynamically" so that I don't have to create image files for each element. This would make it harder when one app uses one color for objects and another uses something else.

Basically what I want to know is this: Is there any way, with iOS, to create drawable resources dynamically instead of using static, pre-rendered images?

First,

No there is no XML for adding style to buttons or other views.

Second, you can implement the same type of design process by creating a constants file using NSObject, and then just add custom functions, variables for creating buttons... Something like:

+(UIButton *)create_styled_btn(float corner_width, UIColor color) { .... return btn; }

And of course you can dynamically change the style of objects through code, just like in android. XML in Android is of course static, so maybe I'm reading your question incorrectly.

All the best.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM