Domanda

I'm currently making apps for iOS, and I had a quick question about making UIViews. In the process of designing a UIView, I was wondering if everything should be based off of the bounds of the rectangle that contains my view.

For example, the one I'm currently working on is designed as a header that only occupies the upper 25% of the screen. Despite this intention, should I still design the code so that if the view were to occupy the entire screen , it would still work?

To provide a scenario, lets say I need to draw a line. Should I just draw it 20 pixels across, or should I always go 30% of the width of my rectangle.

I understand the concept of reusability, but if I'm designing this view only for this particular purpose, is it acceptable to make it somewhat rigid in nature?

È stato utile?

Soluzione

Designing for change and reusability is always a good practice. However, as you have also realized, it introduces overhead which can sometimes outweigh the benefits of the flexible design.

I would say that it is fine to hard code some values if the view is used only for a particular purpose with a particular size. It is fairly common to create fixed size images for UI components which is just like using fixed size values in your code. Nevertheless, it is a good practice to use constants for all your hard coded values and collect all of these at a centralized place of your code e.g.:

static const CGFloat centerLineWidth = 20.0;

This way you can relatively easily reconfigure your views if something needs to be changed.

Finally, if there is even a slight chance that the view might be used with different sizes, you should go for the flexible design. You can also mix these concepts, e.g. create a view which is designed with flexible width in mind but its height should be a fixed value.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top