Need job

Looking for job in Europe. Please contact thru LinkedIn profile.

Wednesday, November 29, 2017

Text kern/letter spacing in Xcode Interface builder

Sometimes designers uses different kern, not default.
How to change it with minimal time?
Add inspectable text attribute.

Here is ready-to-use code for UIButton.
Very easy transformable to UILabel.

extension UIButton {

    @IBInspectable
    var letterSpace: CGFloat {
        set {
            let attributedString: NSMutableAttributedString!
            if let currentAttrString = attributedTitle(for: .normal) {
                attributedString = NSMutableAttributedString(attributedString: currentAttrString)
            }
            else {
                attributedString = NSMutableAttributedString(string: self.titleLabel?.text ?? "")
                setTitle(.none, for: .normal)
            }

            attributedString.addAttribute(NSKernAttributeName,
                                           value: newValue,
                                           range: NSRange(location: 0, length: attributedString.length))

            setAttributedTitle(attributedString, for: .normal)
        }

        get {
            if let currentLetterSpace = attributedTitle(for: .normal)?.attribute(NSKernAttributeName, at: 0, effectiveRange: .none) as? CGFloat {
                return currentLetterSpace
            }
            else {
                return 0
            }
        }
    }
}

Thursday, February 9, 2017

Swift weak delegate

When you need to declare weak delegate property you may caught " 'weak' may only be applied to class and class-bound protocol types, not 'SwipePickerDelegate'".


Apple mentioned this in docs here:
https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html#//apple_ref/doc/uid/TP40014097-CH25-ID281

So, all you need is add "class" keyword to protocol.


Tuesday, January 31, 2017

Couldn't create mapping policy for class named () - Core Data migration error

Its easy to fix it.
One of possible reasons is Policy class name w/o namespace.
On the image below a PRODUCT_MODULE_NAME mentioned with red.


If you don't now the name, here is the trick to find out.


Thursday, February 25, 2016

To fill any image with color

@implementation UIImageView (Utils)

- (void)setImageRenderingMode:(UIImageRenderingMode)mode
{
    if (self.image)
    {
        UIImage* newImage = [self.image imageWithRenderingMode:mode];
        [self setImage:newImage];
    }
}

- (void)fillWithColor:(UIColor*)color
{
    [self setImageRenderingMode:UIImageRenderingModeAlwaysTemplate];
    self.tintColor = color;
}

@end

Tuesday, March 31, 2015

useful localizable category for NSString

"Just code post"

@implementation NSString (Localizable)

- (NSString *)Localizable
{
    return NSLocalizedString(self, nil);

}


Using like this

NSString *newTitle = [@"settingsBarTitle" Localizable];

Tuesday, October 14, 2014

iAd error on iPad


Recently, when I was testing iAd app on iPad, I've got an error when accessing root view.
EXC_BAD_ACCESS code=2




Stack trace was looped infinitely.



We need to analyse the algorithm and change it to prevent call [self view] from error method of iAd delegate.

In my case it was easy:
During UI load my iAd banner already hidden.
I just check if banner is hidden and do nothing.

Here is a link to my post on stackoverflow - http://stackoverflow.com/questions/16471240/using-iads-on-ipad-crashes-after-huge-number-of-calls-to-bannerviewdidfailtorec/26025212#26025212











Friday, July 18, 2014

Xcode auto layout - how to fill removed control space automatically

How to automatically transform picture 1 to pic 2?

pic 1
pic 2

Its all about constraint priority and redundancy.
Priority of space between grey and blue element is higher that grey and bottom of screen.

 

Now if remove blue you will get Pic 2 scene.