Coursera - Intro to IOS Development Part 2

After doing the much-needed consolidation entry for my 'basic' app, I feel like I strengthened my understanding of various concepts:

General use of Xcode including VCs and Storyboard etc
Assets and using the 1x, 2x and 3x
Use of the button style custom struct
A custom struct for specific info (Buffy Characters)
Multiple VCs and successful segues!
Random function within arrays (something I have admittedly done quite a lot before)
Constraints, alignment, style etc. with images, buttons, labels

So lots of useful stuff! Now I've done that, I'm ready to tackle 'Week 2', which I will do some of now and more later. 

Supporting iOS on iPhone and iPad

This is not just having the same layout on each, but having an adaptive approach. 

Mark has done something with terminal and git but I don't get it - I tried accessing mine but not working - must be to do with where it is saved etc. Mark recommends this so something to look at another time!

I think I know where this is going - it must be that you can do a separate view for how it appears on iPhone and a different one for iPad. 

All assets saved - same issue as usual that Mark has them available after a challenge (one question - passed) and then got them. 

Clip to bounds - on the image view options, this is automatically selected to trim off non-needed bit of the image. General rule of thumb is to use aspect FILL to keep the original looking image. 

OK, I've gone ahead and just done all of the image bits in, then will compare with what Mark did. More proactive learning. Yes, Mark also thought stack view for a horizontal row!

Some good bits about resizing - you can add in a width or height property constraint, then edit it to less than or equal to, then put in the aspect ratio, and change that to 1:1. Some other useful constraint stuff  - putting something in vertical centre of another object - this means that only the left/right constraint is required. Cool. Another thing to remember is not to go overkill - if I have pinned the left and right, then it does NOT need horizontally in centre as well. I've done that before. 

OK, moving onto the next part...

I'm skipping through this now - seen enough comments to realise that this whole constraint on other devices is just a pain in the ass. Picked up some useful parts but all just confusing. 

There is an option for the 'installed' bit to go between iPhone and iPad. Will come back to that if ever needed.  Didn't bother with the 'shape' challenge... I should have a go. OK, let's go back to that! I tried - not enough info for different position and spacing of objects. A poor week this has been from Mark!

That will do for now - week 2 completed but not impressed with Coursera. I'm going to cancel the subscription and look at what raywenderlich has, as I've already got a subscription with him. Possibly Paul Hudson Hacking with Swift as well. 

Actually, just going to crack on with Week 3 as I have some time!

Custom Text Fields

Cool, this will be within a new app - it looks exciting!

OK some complex stuff below. First off, textStyle for a label as a separate class. Then some placeholder stuff - 

class TextStyle: UITextField {

    

    override func awakeFromNib() {

        super.awakeFromNib()

        

        backgroundColor =  colorLiteral(red: 1, green: 1, blue: 1, alpha: 0.2539906443)

        layer.cornerRadius = 5.0

        textAlignment = .center

        

        

        if let p = placeholder {

            

            let place = NSAttributedString(string: p, attributes: [.foregroundColor: UIColor.white])

                 attributedPlaceholder = place

                 textColor =  colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)

        }

        

     

    }

}



The ColorLiteral bit means a click option for the colour - not all of that code! Anyway, this is complicated stuff but basically means what will go into the text field. Another point is what is on the simulator is not what is on the screen - this is an issue that the 'preview' feature with SwiftUI solved. 

Again, a lot of code to achieve something that seems quite straightforward. Using the old language with NS is evident of that. 

Input Accessory and IBDesignable


@IBDesignable - show the changes that happen in a class to show in the interface builder. Again, this is something that SwiftUI already does - one of the many positives of that. 

When the text field is all good, a keyboard will come up when selecting to type in it - nice! You can then change the keyboard style - to decimal in this case. 

Programming calculation button, rather than creating the object etc. 

let calcButton = UIButton(frame: CGRect(x:0, y:0, width: view.frame.width , height: 60.0 ))

        calcButton.backgroundColor =  colorLiteral(red: 0.9613958333, green: 0.5450937919, blue: 0.2006272624, alpha: 1)

        calcButton.setTitle("Calculate", for: .normal)


Tip from Mark, always do .setTitle, not .title etc. 

Selectors - putting in specific code which is again, all very fiddly. 

let calcButton = UIButton(frame: CGRect(x:0, y:0, width: view.frame.width , height: 60.0 ))

        calcButton.backgroundColor =  colorLiteral(red: 0.9613958333, green: 0.5450937919, blue: 0.2006272624, alpha: 1)

        calcButton.setTitle("Calculate", for: .normal)

        calcButton.setTitleColor( colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0), for: .normal)

        calcButton.addTarget(self,action: #selector(MainVC.calculate), for: .touchUpInside)



So after all this there's an error...Will have a look at the discussion bit to see if there is any help...

I figured out something - that I had renamed the VC but not updated it in the properties - knew that would come up! As to why all the other bits don't come up...who knows! I had also forgotten to put the customizeView bit in the awakeFromNibs in that customTextStyle thing. 

So that's all sorted for now - all very laborious but I least I know how. After all this, I will have to do a consolidation bit again...

Here is the video clip to watch  https://developer.apple.com/videos/play/wwdc2019/413/

But 54 minutes? No thank you! Too passive a way and a waste of time at the moment. 

And that's the best place to stop for today!

Comments

Popular posts from this blog

Coursera Introduction to Programming in Swift - Part 4

Coursera - Intro to IOS Development Part 1