Set object properties depending on Size Class in iOS8 - xcode

I am new to iOS development, I have read about size classes, I have a question about setting properties (or just calling methods with some parameter) depending on ViewController's size class. I am developing a simple radio app, for app design I decided to use Collection View in which I want display logo image. Because I develop universal app and I want to place images in 3 columns or rows on both iPhone snd iPad versions, I need 4 Collection Views for iPhone and iPad for portrait and landscape orientations. For example for iPhone's Collection View I set 75x75 image size for cell, for iPad's 200x200. So for one object (radio station) I need to create 2 image sets, because I do not want just to use the biggest iPad's images on iPhone for two reasons: higher CPU usage, scale issues.
So question is which is the best solution to create objects in array for Collection View with appropriate image size depending on Size Class? Is it good solution to use UITraitCollection to determine Size Class in the viewDidLoad method?

You question indicates you need first to take time to learn some stuff on iOS.
Like you I had to start and learn : it is no problem.
have a closer to auto layoutin iOS
www.raywenderlich.com
then see how easy and fun is iOS development (just need to practice to understand how easy it is). Here is a tutorial for collection views:
www.raywenderlich.com
image scaled
in your image asset
place image with name terminated with
nothing, #2x, 3x
-> easy way to scale image : I use sketch.

Related

Autolayout needed if only support one orientation?

Is Autolayout needed to setup for any subview, if my application only support one orientation (e.g., landscape right), applied for all UIViewControllers?
Yes, of course in the case of using animation I agree. But for the normal case, do I need AutoLayout?
Note: I am using XCode7, Swift, ios9
Understanding Auto Layout
Auto Layout dynamically calculates the size and position of all the
views in your view hierarchy, based on constraints placed on those
views. For example, you can constrain a button so that it is
horizontally centered with an Image view and so that the button’s top
edge always remains 8 points below the image’s bottom. If the image
view’s size or position changes, the button’s position automatically
adjusts to match.
This constraint-based approach to design allows you to build user
interfaces that dynamically respond to both internal and external
changes.
Unless you are making an app for one specific screen size, you will want to
use Auto Layout.
Use cases:
You want to support different size classes.
You want to support different screen sizes.
The content displayed by the app changes.
The app supports internationalization.
The app supports Dynamic Type (iOS).
Most of these changes can occur at runtime, and they require a dynamic
response from your app. Others, like support for different screen
sizes, represent the app adapting to different environments. Even
through the screen size won’t typically change at runtime, creating an
adaptive interface lets your app run equally well on an iPhone 4S, an
iPhone 6 Plus, or even an iPad. Auto Layout is also a key component
for supporting Slide Over and Split Views on the iPad.
Auto layout is not required at all. Even for multiple orientations.
However, If you don't use it, you'll have to manage placement for all the different sized devices yourself. So you might as well use it.

equal spacing between uiimageview using size class

I'm trying to add four or (more in future) uiimageview in ipad application landscape mode. I want equal spacing between each uiimageview. I used wRegular hRegular format to build the application and used few constraints, but when i try to run the application in simulator i'm getting different result for different iPad devices. How can i achieve having equal spaces between uiimageview irrespective to size of the screen ? Below is the screen shots.
iPad2:
iPad Air :
iPad Retina :
Resizable iPad :
Auto Layout is a system that lets you lay out your app’s user interface by creating a mathematical description of the relationships between the elements. You define these relationships in terms of constraints either on individual elements, or between sets of elements. Using Auto Layout, you can create a dynamic and versatile interface that responds appropriately to changes in screen size, device orientation, and localization.
Try this link to learn about Size classes and Auto layout.
http://www.appcoda.com/introduction-auto-layout/

Custom elements in watchkit

I was reading Apple Watch Human Interface Guidelines and i'm curious if there is any way in displaying custom UI elements, other than those provided by default by Apple (like tables, buttons or labels). How did they managed to do this:
Did they use images?
While we haven't seen everything that Apple are doing with the core Watch OS apps, it is already clear there are many API functions that they are reserving for their own use at this stage. It's almost certain they were using some of those API functions to create these views.
There is no way to create truly custom UI elements with the current WatchKit API (i.e. entirely new custom classes doing custom drawing). That said, with some creativity, it would be possible to create most of the interface you depict with the current tools available to third party developers. This is almost certainly not the way Apple created it, but you could:
Create a group.
Put inside the group a button with a background image that represents one state of the coloured circle.
At runtime, visually animate the button image as needed by swapping through multiple images that rendered the various states of progress of the circle x colour options. Yes, the starting point would be thinking about 360 images for the circle states x the number of tints. (It is possible to apply a tint to a template image in WatchKit, but as far as I am aware you cannot apply a gradient.)
Add two labels to the group for the large number and subscript, and align both of these to be centred vertically and horizontally in the group.
You can set the tint of the page title at top left by setting the global tint of the application. By changing the global tint at runtime you could change these for each page.
It is not currently possible to change the colour of the page dots at the bottom. These are not set by the global tint and it is not possible currently to change these programatically.
Apple have indicated that later in 2015 third party developers will be able to build fully native apps, but even then, they have not given any indication of whether the API functionality available to us is broader, or whether our API will be essentially the same as it is now, with the one addition that at least some of the current WatchKit App Extension code will be able to run on the device when the iPhone is not present/charged.

Using size classes and autolayout in xcode 6

I'm looking for some help with the new storeyboards and size classes in xcode 6. I'm looking to build a fairly simple interface with a few labels and text field, however I'm having problems making this look correct for the different devices.
As you can see from the attached image iphone 6 picks up the constraints and size set for the iphone, which looks daft (forcing the label for Score, for example, closer to the left because of the constraint) and doesn't make use of the screen size. Is there no way in xcode to build a layout and have it proportionately adjust to the screen size? Buttons and labels increase in size by x amount?
I can build completely separately for ipad and iphone and was happy to do this in previous versions of xcode but this seems to be defeating the whole point of size classes, and even if I was to do this my problem is still the iphone 6 and 6 plus which would pick up the iphone layout and look ridiculous.
I'm tearing my hair out with this so would appreciate any help.
Maybe constraint the lower elements to the bottom of the screen rather than the top. Other than that I think you don't have many options.
You can change your layout for different views using compact and regular widths and heights. Click on wAnyhAny at the bottom of your screen. This will provide a grid view pop up, which lets you customize view for different screen sizes. As you select different boxes, the bottom will tell you what size the view applies to.
You can change four things in a size class:
1. The constant for a constraint
2. If a constraint is installed in the view hierarchy
3. If a view is installed in the view hierarchy
4. The font used for many types of views showing text
This means if you want a different label or constraint for your iPad view, you can add that constraint just for that view using size classes.

grow or shrink UIImageView frame to fit the entire iPhone screen via AutoLayout?

So I'm still getting accustomed to the world of Auto Layout in iOS 6 and it's been a fun (or in plain English -- tough) migration coming over from strings & struts.
I have a UIImageView that's the background for a game I'm working on. Here's what a regular 3.5" Retina Display looks like in Interface Builder:
but if I change the "Size" pop-up in the Simulated Metrics field for the content view to "Retina 4 Full Screen", here's what I see:
And you can see the ugly black bar appearing along the bottom edge of the simulated iPhone 5 screen. This same ugly black bar makes it over to the compiled app running in the iPhone 5 simulator.
Are there any attributes or constraints I can apply via Interface Builder to get the UIImageView's frame to size correctly for the appropriate iPhone device screen size?
Or do I have to enter in constraints via code? (ugh)
I've watched the three WWDC videos and if the engineers covered the topic of sizing a view to fit a parent, they must have glossed over it really fast because I've haven't yet found or heard a decent method to get both UIImageView and NSImageView to size correctly to their parent views under both the iOS and MacOS side.
From what you're showing here, I think that what you want to do is drag the image to meet the bottom of the superview so that it takes up all of the space you want. On the bottom right in the IB view you will see a small, grey pill-shaped set of 3 buttons. Click the center one (once you have your imageView selected). It's the one that looks a little like this: |--|. It will bring up a list of constraints. Once you have done that, select "Bottom Space to Superview". You should then be able to switch between phones and have the image resize automatically.

Resources