I have text displayed within a UIView which again is located within a UIScrollView.
The font size/size of the text should change its size based on its distance from a certain point on the screen.
There are many of these items on the screen which at a high rate need to rerender the same text at different sizes.
How can I optimize this in order for the text rendering to be less of a bottleneck?
Related
i wonder what is the best practice for ui design for iOS regarding ui element sizing, especially buttons. In my example all buttons are based on images, no text.
I see two approaches
Absolute Sizes
PRO:
image based buttons do not need rescaling, avoids blurriness
simple setup in interface designer
CON:
buttons look smaller on bigger displays (ipad2 vs. iphone 4) relative to other ui elements
Relative Sizes
PRO:
buttons look better in whole ui appearance across all display resolutions and densities
CON:
buttons may look blurry
interface builder constraints will get a bit more complex
Did i forgot something? Or did i get it wrong?
For now i was designing the ui completely relative to the screen. So lets say a button had the width of 10% of the screen width and an aspect ratio of 1:1. When the ui was completely relative, everything seemed consistent across all devices. But my questions started in the scenario of #2x density buttons. The iphone 4 has a width (portrait mode) of 640 while the ipad2 has an width of 768. Should i create my #2x, 10% button image with a width of 77px or 68px? I would say 77 because downscaling is better than upscaling.
Well, this leads me to my question:
What is the best practice to design the UI? How should we handle the image design for buttons?
Usually the problem is the text got stretched.
You can set the strech area by following this:
https://developer.apple.com/library/ios/recipes/xcode_help-image_catalog-1.0/chapters/SlicinganImage.html
If you use gradient and it became blur when stretched, you need to draw the gradient using Core Graphics.
I'd say there's no ultimate approach for laying out image buttons in iOS and it always depends on what you're trying to achieve.
In your case I would recommend the following approach:
Use layout constraints to position your buttons properly. Use only
spacing constraints, no width or height constraints!
Set the images for your buttons (either in Interface Builder or in code). Make sure to provide each image asset in all three resolutions #1x, #2x, #3x.
If you have multiple buttons in a row give each of them a different horizontal compression resistance priority. This ensures that in case your buttons don't all fit on screen one (or more of them) will be scaled down to fit.
When assigning an image to a UIButton, that image will determine the button's intrinsicContentSize. Thus, the button will automatically take the size of the image (if no other constraints with a higher priority are present) and it will only scale down if absolutely necessary (see number 3. above).
This approach is only possible if you still leave flexible spaces next to the buttons. If you intend to split the screen equally into three columns for example and each button should take the whole width of a column you have no other choice but do let the system scale down the images for devices with a smaller screen size. It always depends on whether you can allow the buttons to size themselves or if you need to force a width (or height) on the buttons from their superview.
I have just started learning IOS Development so my knowledge to it is very little.
I am building my layout for my app. I need my app to run on all devices . I have read somewhere that you should never use a constant magic number when creating constraints and always use standard values. I want to support my app for all resolutions
whenever I set standard value it's '0' so does this means that I have to play with multiplier values to have similar spacing
And kindly let me know when we can use constant value and when we have to avoid.
Most of the times you need to space the views evenly in the screen . This makes the view look similar on all devices (like on a bigger screen it should be equivalent to scaled version of how it looks on a smaller screen).
For Eg. If you need to space 3 views horizontally and equally on a view. If you set the height/width of the buttons to a magic number, say 100 pixels. The 3 subviews would look relatively smaller on a iPhone6+ screen than say on a iPhone5 screen.
This is when you use multipliers. Like height/width of buttons = 0.2 of superview.
On the other hand you need to use magic numbers in some cases.
For Eg. You are creating a canvas on the screen in which the user will draw with a menu panel on the left. You know the menu panel fits in say a 50 pixel strip on the left. So if you set the size of the menu panel by a multiplier, then the menu panel will become larger on bigger screens. This would somewhat nullify the advantage of having a bigger screen to draw.
This is when you use magic numbers as you know the menu panel needed to be no larger than 50 pixels.
(Note: never use magic numbers directly. Create constants like k_menu_bar_height = 50. Then use this constant wherever you need. This is much more readable and helps in the long run from a maintenance point of view)
So here's my problem. I am currently trying to create a rectangular enclosure using four more rectangles as borders. So it would look somewhat like this. Keep in mind each side is individual so a rectangle with a border wouldn't work.
Now the actual problem comes with different screen sizes. Specifically the 4s. Since the screen is shorter than other phones, how would I resize the rectangles on the side to fit the height? One of my options was detect the screen size, and then set the height of the rectangle, but I was wondering if there was an easier way since I'd also have to deal with all the other screens.
Rather than hardcoding, you can get the maximum screen size with CGRectGetMaxX(self.frame), similarly there are CGRectGetMidX and CGRectGetMinX. With these three methods, you can set proportional height/width and coordinates for the rectangles.
I would like to know how people have reliably (from a system set dynamic text size POV) worked with smaller size fonts on the apple watch, with normal text and timer elements.
The former can have their text size assigned in their attributed text, however the preferred fonts (or descriptors) used to create the new smaller font don't seem to update their size with respect to the watch's dynamic text size setting.
The latter can't have their text size assigned directly though using their minimum text scale and resizing them in the storyboard you can shrink them to a given size ok. The problem from a dynamic text size POV is that these timers DO update their size from the dynamic text size setting but if you've used the storyboard scale and minScale route to resize them then you can run into trouble when larger text size is selected by the user and no longer fits in the smaller size frame so is truncated as ...
Essentially dynamic text size on the watch doesn't even seem to be properly exposed in any of the API so you can't even adapt UI element sizes in code depending on what the current system dynamic text size is set to.
Cheers
I am working on a BlackBerry App that has a lot of ImageButtons, LabelFields and MessageBoxes. What appears to be perfect on one screen size, seems a mess on the other. For instance, Vertical Field Managers that are neatly aligned center with LabelFields, are left/right aligned on bigger screens. Images that cover the width of the screen appear too small on larger screens. Is there some mechanism to auto-align and dynamically change images with respect to the screen size. Any ideas and documents that can help in this regard?
Here are some tips for making screens that look good on almost all devices:
Use less images. If you have to use images, use atleast 3-4 for different screen sizes. for example if you need to have an image as the screen header, use images with widths 320px, 480px and 640px. Load image depending on the width of the screen.
Do not use pixel measurements. Use point measurements instead. Most of the devices are similar in terms of physical size, whereas they have huge difference in pixel density. Using this you can have a screen which will look exactly identical on curve (320x240), bold2 (480x360) and bold 4 (640x480). If you notice, they have the same aspect ratio and similar physical size.
Do not hardcode positions. Instead use FIELD_HCENTER and DRAW_HCENTER etc for fields.
Do not use fonts with fixed pixel height. Use fixed point height instead.
If using custom fields, make sure that they can automatically expand according to device and pixel density.