Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 513
Phil Ringsmuth Avatar asked Sep 19 '13 11:09

Phil Ringsmuth


People also ask

What is the equivalent of XML in iOS?

Like Android XML, iOS also used XML file for Designing the UI part call Storyboard or nib file. if you could Right-Click and select Open As "Source code" you will find XML code their. The way android used Layout for UI is different from iOS.

What is not an advantage of using vector Drawables?

The drawback is that they might take longer to draw, etc since there's more of parsing and drawing going on than just using a bitmap. This should although be neglectable if you keep your vectors simple.

What is InsetDrawable?

android.graphics.drawable.InsetDrawable. A Drawable that insets another Drawable by a specified distance or fraction of the content bounds. This is used when a View needs a background that is smaller than the View's actual bounds. It can be defined in an XML file with the <inset> element.

Which function is used is to load a drawable image resource?

Drawable myImage = ResourcesCompat. getDrawable(res, R. drawable. my_image, null);


1 Answers

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.

like image 126
virsunen Avatar answered Oct 27 '22 15:10

virsunen