PaintCode - update view and pass variables - ios

Does anyone know of a comprehensive tutorial on implementation of PaintCode, using variables with it, and getting the view to update. I am struggling my way through it. I have built a custom class, and linked a view controller, with a UIView, and I can see the simple graph I made. I have linked it up so that it is #IBDesignable & #IBInspectable and both work fine. I am just not sure how to pass a variable through to the UIView.
I also have absolutely no idea how to get the thing to update when the variable changes.
Any assistance in this would be great, it has taken all day so far and I feel nowhere closer to solving the issue.
I do appreciate your time and effort.

There a many tutorials in PaintCode home page and at this other website, good lucky
However to access the values you create you just need to create an outlet from the UIView to your UIViewController class and class myViewName.myVariableName = myValue
As this step by step tutorial explain

The only tutorials I've found are the PaintCode website.
There are three things that I tend to adjust when trying to add/remove parameters to make my drawings more customizable via code.
When you click on a canvas, there is a drop down menu in the inspector that allows you to include a draw method, an image method, or both when you export the style kit.
When selecting the color in the color palette, there is a drop down menu in the upper right that allows you to make the color a parameter, so that when you export, you can set the color via code.
Add a frame to the canvas and set the constraints in the inspector. These constraints are the old style layout constraints that are very annoying, but doing this inserts a rect parameter in the exported methods which you can set in the code as well.

I don't know any other good PaintCode tutorials - over and above - the tutorials suggested. But after some research, I think I know the answer to your problem:
Background before the answer: I had the same problem. For example, you have a good sized image (created by PaintCode) that works on all iPhone device except the iPhone 4S.
To solve my issue:
Open PaintCode & find the “Frame” button.
Learn a new word “Parametric”. That is what we are dealing with. When the frame changes in size, you set whether the objects inside the frame change size or stay the same.
Watch the Dynamic Shapes tutorial on the PaintCode site. All of the answers are within this short youTube video. It took 5 times of watching it until I have extracted all of the information I needed to get it to work.
If you want the more details, keep reading:
#IBDesignable
class beerViewClass: UIView {
override func drawRect(rect: CGRect) {
SecurityStyleKit.drawCarDashboard(frame: self.bounds, wageIncome: "yo!")
}
}
Notice I can set the frame size as I have multiple views of the same image. Also I can send in variables to the drawCarDashboard.
Within PaintCode, put the objects you want to scale / shrink inside the frame.
Set the Springs and Struts for each item in the frame. For example, do you want it to shrink, stay vertically centered, etc.
Export your StyleKit to Xcode.
in Xcode, using Storyboard or code, add the UIViews to your View
Controller
Add a new Swift file.
Change the blank Swift file to a subclass of UIView & add code (see example)
In storyboard view, select the views that were added.
Set the view to the class you wrote (beerView)
I hope that helps. I hope my explanation was clear.

Related

How to get a portion of a UIImageView around a point

Is it possible to get a portion/area of an UIImageView around a point, either a circular portion of a given radius or quadratic?
While my users are moving a pin on a UIImageView I would like they could see a zoomed area around that point into another UIImageView.
How can I get that portion?
Consider using this project (Swift), or this one (Objective-C).
UPDATE.
I just update code from first link to be compatible with Swift 2 and add some features like #IBDesignable.
So, to get magnifier in your project you need few steps:
Download MagnifyingGlassView and MagnifierContainerView from here and add them to your project.
In Storyboard open your controller and select UIImageView which you want to magnify.
Select Editor->Embed in->View.
Select created view and assign class MagnifierContainerView. Make outlet from this view to your controller.
In viewDidLoad add this code:
magnifierView.magnifyingGlass = MagnifyingGlassView()
Where magnifierView is outlet to view you created in step 3.
Colour, width or size you can specify through Attributes inspector for MagnifierContainerView in InterfaceBuilder.
Thats all. Complete example you can find here. Hope it'll help.

Load Multiple Separate Swift Files into Main Container View

Ok, so I will apologize in advance, but I am a complete noob to Swift and iOS development, but I really want to learn to code. I have followed quite a few tutorials and so forth online, but cannot seem to find an answer for this problem I am having. There has to be a simple solution to this because it doesn't seem like a very hard issue but the googles are not being my friend in finding an answer. I do not want to use storyboards because I want to learn the real meat and potatoes. I am using OS X 10.11, Xcode 7, writing the app for iOS 9, universal.
So, I designed a calendar app with quite a unique display, UI, and functionality than the other grid based calendars out there. I have a UIView that I want to be a container to hold the other views I need and pull them into the container view. The files I have are the included ViewController.swift and my custom files ContainerView.swift HeaderView.swift, CalView.swift, and CalDetailView.swift. I set classes for each file, the HeaderView is a basic UIView, CalView is a horizontal UIScrollView that enables pagination for the different calendar views like week, month, day, year, and so on. The CalDetailView is also a horizontal UIScrollView that will display event details to the user and also be the primary action area for the user for editing, adding events, etc.
Currently the ContainerView loads just fine and I can do whatever I want there and can create these other subviews without a problem but only in the ContainerView file. I want to keep these areas separated out into different files for my sanity and add them into ContainerView UIView as subViews with AutoLayout and everything, just like I am able to do inside the ContainerView file, but it would be enormous and I don't want that.
I believe the proper way to do this is to add these subViews under the viewDidLoad() method of the main VC and create my AutoLayout constraints in the VC file, then I just want to load my subViews in the ContainerView file and build the screen. The separate subView files will contain all of my drawing code and touch events and so forth for the views.
Here's a simple wireframe of what I am trying to accomplish...
The whole window is ContainerView.swift the rest, subViews of ContainerView.
WireFrame
This question is a little open ended and non specific, but let's ignore this for now (it is your first time), in future please be more specific, this is the kind of response a tutorial might be better providing. You will have enough to do, without avoiding Storyboards - feel free to use them.
In any case it is fine.
Given a UIView subclass MyView, in your main view controller:
override func viewDidLoad() {
super.viewDidLoad()
....
let myView = MyView()
self.view.addSubView(myView)
myView.frame = ... OR <SET CONSTRAINTS>
....
}
Essentially you will initialise those view subclasses and add them as appropriate.

Single view iOS app with custom drawRect

I though I understood this, but I can't get it to work:
I'm trying to create a very simple app, to test various things (OK - it's an app to estimate Pi using the Monte Carlo technique by simulating throwing darts at a board).
I have a single view iOS app (e.g. from the single view template) on which I've simply got one UIButton (to launch the app) at the bottom and a UILabel at the top to show the results.
The view controller is a custom subclass of UIViewController call PiCalcViewController; the view is a standard UIView filling the whole screen.
The app works but now I want to be able to draw a graphic representation of how the simulation is going the middle of the screen, which I'll do in my view's drawRect (right?). So I thought that I'd create a new file (PiCalcView) an Objective-C class, make it a subclass of UIView and then, in IB, drag out a new view in the middle of my view controller and change it's class to PiCalcView.
Great, except that PiCalcView does not appear in the drop-down class list in the inspector.
Questions : Any idea what's wrong and is creating a subview of my UIView like this the right way to do it?
Type the class into the custom class section in the Identity Inspector.
OK - quitting and restarting Xcode appeared to do the trick.
Thanks for the tips - being new to Xcode & ObjC, I didn't know if I had the right technique.At least I know now.

Create custom UIButton with multiple images and shift Label and maybe add properties

for an iPad application in ios5.0 and arc, I need to create a button that has an image covering the entire button, and needs to have another transparent image at the bottom half of this button image OR have the button text label covering the bottom half of this button image.
In posts on this site I've read that using button subclass to just change the appearance of the UiButton should not be done. However, if I don't subclass, can I add these transparent image/and shift the button label? if so, how?
In case I need to add properties to the button, what is the best way to go about it.
If subclassing is the only option, can you also pls give pointers on what are the methods that i must absolutely override and any other such memory/performance considerations that I must keep in mind
Pointers to Any tutorials or third party libraries would be most appreciated.. Thanks in advance for all your help
I don't agree on "subclassing UIButton is not good". That's exactly why inheritance and subclassing mechanisms exist. In all platforms, the framework provides a base foundation for general needs, and you do extend them in the case standard stuff does not satisfy your needs. And you do it by subclassing.
As long as you know what you do, and what you do works for you and solves your problem, you're fine.
When you subclass UIButton, depending on what you actually want to achieve, you may want to override init:, initWithRect:, layoutSubviews:, awakeFromNib: methods.
Inspecting some subclasses would also help:
https://github.com/ardalahmet/SSCheckBoxView
https://github.com/ardalahmet/CopyableCell
For UIButton, you can inspect this component. Source code may help a lot.

UIView with UIButtons not showing up prior to click or rotate

I've been banging my head with this issue for the last two days. Googled a lot but wasn't able to find the answer yet, so I decided to request some help here. Let's see if I get any luck.
I'm coding a reusable control that consists of an UIView with a variable number of customized UIButtons. I implemented initWithFrame:, initWithCoder: and drawRect: where the buttons (which are built prior to drawing) are actually added to the view. Everything is done programmatically since the UIButton content should be supplied when using the control, so there's no XIB for this UIView.
This UIView, let's call it CustomizableBarButton is then used in an UIViewController, let's call it MyTestViewController with a view on it, let's call it customizableBarButtonView.
MyTestViewController's GUI was set on IB where an UIView was tied to customizableBarButtonView (the class was matching accordingly).
MyTestViewController's is a pretty standard class except for the viewWillAppear: that initializes the buttons and passes them to the CustomizableBarButton along with some other options.
The issue is that everything works perfectly...except for the first time!
I mean, when I run the app on the simulator (I haven't tried it on the iPhone yet but I strongly believe that it's not an hardware issue) the MyTestViewController shows the customizableBarButtonView background but not the buttons. Now when you click on the place where a button should be all the buttons suddenly appear!
I'm puzzled since the CustomizablebarButton drawRect: runs before the strange "click n'appear" effect and the buttons are actually added to the subview.
Another hint that my help: if you don't click on the buttons (so you still got no buttons yet) but rotate the device they will also appear as if by magic!
It is probably something very simple but I'm missing it and I'm going nuts...
Can someone lend a hand on this, please?
Thanks in advance!
You said you're adding the buttons in drawRect:. Don't do that. You need to add the buttons in your init methods.

Resources