Swift 2.0, UILabel and setTranslatesAutoresizingMaskIntoConstraints - uibutton

I have upgraded my xcode and now using Swift 2.0. I have an issue with all components which I set at runtime and used to rely on
setTranslatesAutoresizingMaskIntoConstraints
It seems that the method is no longer available and I had to comment out the code. As a result, all positioning is messed up....(impacting, buttons, labels, images shapes)
Any idea how to approach this problem?

The method did changed in Swift 2.0
button.translatesAutoresizingMaskIntoConstraints = false
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instp/UIView/translatesAutoresizingMaskIntoConstraints

Related

setApplicationIconImage Deprecated in 10.10 - Alternative?

I'm seeing here in changes page that setApplicationIconImage was deprecated. Man I couldn't believe it.
https://developer.apple.com/library/mac/documentation/General/Reference/APIDiffsMacOSX10_10SeedDiff/frameworks/AppKit.html
What is the an alternative for this now? Is there one that works in older versions then 10.10 too? If not its ok i can do version check and do setApplicationIconImage for <= 10.9 and the new way for >= 10.10.
Thanks
The setApplicationIconImage method did not get deprecated or removed.
Apple only changed the header to SHOW it as a property instead.
setApplicationIconImage IS the setter for the property. properties are only syntactic sugar for two 'standard' methods: a getter (applicationIconImage) and a setter (setApplicationIconImage)
you might get an ARC warning nowadays because it can't see setApplicationIconImage so use the dot-notation on ALL platforms -> no need for a runtime check of 10.10/10.9
It looks like maybe they removed the method in favor of a property. So use this instead.
[NSApplication sharedInstance].applicationIconImage = myNewIconImage
From the NSApplication class reference,
Assign an image to this property when you want to temporarily change the app icon in the dock app tile. The image you provide is scaled as needed so that it fits in the tile. To restore your app’s original icon, set this property to nil. Available in OS X v10.0 and later.

Custom NSCell drawWithFrame:inView method not getting invoked in OSX 10.8

I have an application where I have defined a custom cell and have overridden the method
- (void) drawWithFrame:inView:
This method was drawing my custom cells without any problems as long as I was building my app using Xcode 3.2 on OS X 10.6 or older.
Now I am attempting to migrate the code to build with Xcode 4+ on OS X 10.8. And what I have found out is that my custom cell is not getting drawn anymore. After putting break points and running the app through the debugger, I realized that the overridden - (void) drawWithFrame:inView: method of the custom cell is not getting invoked at all.
My questions are:
1) What is it that makes this method to not invoke at all on OS X 10.8, while it gets invoked and works perfectly fine on OS X 10.6 or older?
2) What alternative do I have to fix this issue?
Thanks,
Mriganka
I am having the same problem, except i am using xcode 4.x on OSX 10.7
Maybe its an xcode 4.x thing?
What I have noticed is that drawWithFrame on my subclassed NSTextFieldCell does NOT get invoked when i call setEnabled (changing from YES to NO or NO to YES) on the parent NSTextField, after initialization of my NSTextFieldCell, but before drawWithFrame on that NSCell gets invoked automatically.
However, if I call setEnabled (after initializing my subclassed NSTextFieldCell) and no change occurs (ie. setEnabled:YES but it is already set to YES), then drawWithFrame does indeed get invoked.
Unfortunately, i need to perform setEnabled from YES to NO to YES, as i want to disable my NSTextField while a server call is being made, and then enable it on the callback. If the callback is (for example 'wrong password'), i need to custom draw the NSTextFieldCell border red.. and I have to do this by overriding drawWithFrame.
My guess is that setEnabled utilizes NSGraphicsContext and does a savesGraphicsState/restoreGraphicsState (perhaps in error), which throws off the graphics context that is utilized in NSTextFieldCell/drawWithFrame.
My guess is that the NSGraphicsContext within setEnabled is ONLY utilized if a change occurs (setEnabled from YES to NO or NO to YES), since when a change DOES NOT occur, I have no issue… I think this would make sense as there would be no point in rendering new graphics to show the user that the view is not selectable or editable, because it does indeed ALREADY LOOK not selectable or editable.
The answer to my problem was to re-draw manually after i called setEnabled, by calling setNeedsDisplay on the NSTextField.
I think this will probably work for you as well, as it causes the draw to occur manually.
glhf!
-Eric

UINavigationBar drawRect Alternative (aka, Need CoreGraphics calls in a category)

I recently discovered that in > iOS5 UINavigationBar does not get its drawRect called. I want to figure out how to draw with Core Graphics in a category.
The end goal I am trying to achieve is eliminating images from my app and have everything drawn at runtime. I am also trying to make this library automatic, so that users don't have to think about using my custom classes.
Is there a way to replace a class with one of your own at runtime? like: replaceClass([UINavigationBar class], [MyCustomBar class]);
Thanks in advance.
Is there a way to replace a class with one of your own at runtime?
In Objective-C this is know as class posing.
Class posing is based on the use of NSObject's poseClass method, which is now deprecated (on 64 bit platforms, including the iPhone).
Alternative approaches have been investigated; you can read about one here, but they do not seem quite to fit the bill.
I found the solution, Instead of messing with draw rect, I just made some methods that draw to a UIImage then set the image as the background view for the elements i am customizing. It makes my custom UI magic again.

How to use NSLayoutConstraint in iOS 6?

My app should support both iPhone resolutions (5 and older) using iOS 5 and iOS 6. When I use autolayouts in IB, on iOS 5 app crashes like this: link
So, I am trying to use NSLayoutConstraint in code, but unsuccessfully yet.
Subquestions:
I am adding constraints in viewDidLoad method, but is it correct?
Does updateViewConstraints invoke by framework? I have never seen that it was invoked.
I tried to use examples from apple's docs, but it was without effect to view.
Anybody knows how to do it?
PS: I know it's possible to make it manually by setting frames, but I would like to use NSLayoutConstraints.
UDP: Yes, I know, that's why i use NSLayoutConstraint in code. I can make condition for determining iOS version. The question is about iOS6.
The AutoLayout feature is only compatible with iOS6 and is not supported in iOS5. Thus the crash
If you intend your app to be compatible with iOS5, you can't use AutoLayout in your XIB files.
You can only use older methods, like the AutoResizingMask for example (which is often sufficient for most cases anyway).

Property anchorPoint cannot be found in forwar class object CALayer

I downloaded this sample: https://developer.apple.com/library/ios/#samplecode/Touches/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007435
If I start the sample app everything is working fine.
I made my own app and copied most of the code into it. There is a method called adjustAnchorPointForGestureRecognizer: But in this method there is a error but only in my app (see screenshot): "Property anchorPoint cannot be found in forwar class object CALayer". I am wondering how I can solve this issue, I don't know what I did wrong. It is exactly the same code from the sample. Anyone can help? Thanks!
Did you import the QuartzCore framework into your project? Maybe that's why it can find the CALayer class
This error is thrown by XCode when it can't find a definition for CALayer. You should add the framework to your project and add #import <QuartzCore/QuartzCore.h> to wherever you are using the class