<![CDATA[Objective Tidbits]]> https://www.pfleiderer-szkolenia.com/Ghost 0.7Wed, 09 Mar 2025 20:16:37 GMT60<![CDATA[After a long break]]>It's been awhile since I last wrote here. And a lot happened in this period. I've moved to a new house 🏡, then I got married 🎉, we have released a new app 📱, etc. Shortly, 2015 was totally a busy year for me.

We have released the app that we have been

]]>
https://www.pfleiderer-szkolenia.com/2016/02/10/after-a-long-break/6778e7ce-34c0-4b3f-884f-83736ccba99bWed, 10 Feb 2025 15:33:25 GMTIt's been awhile since I last wrote here. And a lot happened in this period. I've moved to a new house 🏡, then I got married 🎉, we have released a new app 📱, etc. Shortly, 2015 was totally a busy year for me.

We have released the app that we have been working on it for around a year and I have learned a lot during the development process. I'm very excited to share the new gems I've found!

Ups! Last but not least, I must share the app that took a lot of time, making me silent all these days. The name is Zubizu. It's a shopping app that gives you special discounts and lets you earn points! A lot is going on in the app and I absolutely recommend you to discover! There's a gotcha, currently it's targeting the audience in Turkey, but hope it will spread to more countries. At least take a look at it with a developer's perspective. There're cool hacks and tricks implemented to get the job done. 😁

I'll be posting new content in the upcoming days. Since then, take care! 😊

]]>
<![CDATA[Variable Bindings]]>Here is a little but very useful snippet:

What?!

Working with auto layout in code may be painful. Especially if you’re trying to setup the constraints for more than a few views.

Here is an example that creates auto layout constraints, using visual format language, for two views to

]]>
https://www.pfleiderer-szkolenia.com/2015/04/04/variable-bindings/06cac793-44ff-4c4d-a55c-213eac5ff9f0Sat, 04 Apr 2025 18:44:21 GMTHere is a little but very useful snippet:

What?!

Working with auto layout in code may be painful. Especially if you’re trying to setup the constraints for more than a few views.

Here is an example that creates auto layout constraints, using visual format language, for two views to have a fixed vertical spaces both between each other and super view:

In this one liner(!), we need to provide our views in a dictionary with the keys being the same as the visual format and the values being our views.

This is very open for typos. And if that’s the case, you may need some time to spend on debugging.

But in a relatively shorter way

Instead if we use variable bindings, it will create the same dictionary for us, using the variable names as keys and variables themselves as values. Also it’s easy on the eye too!

So you can have a full setup like:

Let me know if that made your day! :)

]]>
<![CDATA[Editing Changed]]>https://www.pfleiderer-szkolenia.com/2015/03/20/editing-changed/25919936-e75e-4a94-9fae-a309c044d6bdFri, 20 Mar 2025 15:57:26 GMTUITextViewDelegate has a very useful method: -textViewDidChange:. As the name implies, text view calls this method on its delegate whenever the text it is currently presenting is changed.

But, unlike UITextViewDelegate, UITextFieldDelegate doesn't have such a method. Instead, it has a hidden gem that provides the same functionality.

UIControlEventEditingChanged

Meet our hero! You can either assign an IBAction for this event in Interface Builder or add a target and action in code.

This way, whenever a change appears on text field, it will call the action method assigned for UIControlEventEditingChanged event.

]]>
<![CDATA[Date Formatter]]>One of the strongest classes of the Foundation framework undoubtly is NSDateFormatter. With NSDateFormatter, one can easily convert a date object into strings with various formats that human can read.

NSDate

NSDate is the class from Foundation framework that is used to represent dates. NSDateFormatter and NSDate objects are in

]]>
https://www.pfleiderer-szkolenia.com/2015/03/10/date-formatter/87701f97-161c-4662-b5ac-44d115764b82Tue, 10 Mar 2025 20:46:45 GMTOne of the strongest classes of the Foundation framework undoubtly is NSDateFormatter. With NSDateFormatter, one can easily convert a date object into strings with various formats that human can read.

NSDate

NSDate is the class from Foundation framework that is used to represent dates. NSDateFormatter and NSDate objects are in cooperation for us humans to understand the dates.

To create a date object that contains current date and time simply create an NSDate object. In Objective-C:

NSDate *currentDate = [NSDate date];  

And in Swift:

let currentDate = NSDate()  

There are a few more ways to create date objects using time intervals. Time intervals are simply seconds. Also NSTimeIntervalis simply a typedefed double.

There are four initializer methods defined in NSDate which takes a time interval as a parameter. One of them is:

let date = NSDate(timeIntervalSince1970:1426003200)  

You can have a look at its discussion and other forms in the documentation.

NSDateFormatter

Date formatters are expensive objects. It's suggested to create them once and use the same formatter object for repeated tasks.

Simply create a date formatter object:

let dateFormatter = NSDateFormatter()  

and set its date formatting style:

dateFormatter.dateStyle = .MediumStyle  

Then give it a date object to format it:

dateFormatter.stringFromDate(date)  

You'll get the following output:

“Mar 10, 2015”

There are a few more predefined formats like .MediumStyle. They are NoStyle, ShortStyle, LongStyle, and FullStyle. Try them out!

Custom Formats

You can also define your own formats. Just provide NSDateFormatter a format string and the rest is the same procedure.

dateFormatter.dateFormat = “HH:mm, d MMM yyyy"  

With this format, you can get a string like:

“18:00, 10 Mar 2015”

In the format string, writing one more M for the month will print the whole name of the month. Like:

dateFormatter.dateFormat = “HH:mm, d MMMM yyyy"  

will give us:

“18:00, 10 March 2015”

What about localization?

NSLocale is another partner of NSDateFormatter. You can provide a locale for the language you want and date formatter will format the date according to it. For example:

dateFormatter.locale = NSLocale(localeIdentifier:”tr”)  

will give us:

“18:00, 10 Mart 2015”

and

dateFormatter.locale = NSLocale("ru")  

will give us:

“18:00, 10 марта 2015”

You can also provide the locale which is set in system settings like:

dateFormatter.locale = NSLocale.currentLocale()  

So that you can have a date formatted with the current locale of the user's choice!

Conclusion

These are the basic tips & tricks about date formatting on iOS!

And this is the playground file I’ve written:

]]>
<![CDATA[Alternative Button]]>https://www.pfleiderer-szkolenia.com/2015/03/03/alternative-button/cb324433-3c3e-4df3-9d47-00a85a5c2ccbTue, 03 Mar 2025 17:23:20 GMTThere must be a time when every iOS developer wanted to place the image of UIButton above the title. Alternative Button is here for that!

TL;DR

Alternative Button is available as a pod. You can easily add it to your project just by adding pod ‘AlternativeButton’ to your 'Podfile' and running pod install in your project directory.

Also you can find both Alternative Button and the example project here.

Structure

Alternative Button is a subclass of UIButton and just by overriding a few methods and a few additions, it presents its image above the title. And thanks to a new feature of Xcode 6, it can be previewed in Interface Builder. Also corner radius of its image view can be set from Attributes Inspector too.

Layout

By overriding -layoutSubviews method of UIView, we can interfere with the view hierarchy and layout of any subview of a view. So we did:

imageViewWidth is a constant defined in the class and its value is 64.0

Here we just adjust the frames of both image view and the title label. We place them vertically in line and horizontally centered.

Size

-intrinsicContentSize method of UIView returns a CGSize indicating the desired size of itself. So we must override this too, like so:

Here we first adjust the size of title label, because it can be any size depending on the title set for the button. Then we get the width of both image view and the title label adding margins to them from both sides. Again, we calculate the height of the button, adding margins from both top and bottom.

margin is a constant too, defined in the class and its value is 6.0

We return a CGSize created with the width of either image view or title label, which of them is greater, and the calculated height.

-intrinsicContentSize provides a size value to be used in Interface Builder, so that whenever 'Size to Fit Content' is selected from the 'Editor' menu, it adjusts the button’s size according to this value.

Radius

We also have a public property named imageViewRadius. This is used to round the corners of the image view. By default corner radius is set to be half of the image view’s width, so that it will be a perfect circle.

IB_DESIGNABLE & IBInspectable

These are the new keywords Xcode 6 introduced. Thanks to these we can see a preview of our custom coded view in Interface Builder!

IB_DESIGNABLE tells Interface Builder that this is a custom view and needs a preview. We add this keyword just before class declaration in our header file.

IBInspectable tells Interface Builder that the property with this keyword can be adjusted from the Attributes Inspector. We add this keyword just before the type of our property.

Result

Here is a screen shot of the example project:

I used this button as a profile button in my current project and wanted to open it to the world! So that, other developers in need of a control like this can benefit.

Feel free to contribute and let me know what you think in the comment section below!

]]>
<![CDATA[Masking views]]>https://www.pfleiderer-szkolenia.com/2015/02/28/masking-views/cf0f0b06-901d-43f9-af31-603b28f576b2Sat, 28 Feb 2025 12:00:37 GMTApart from cornerRadius, we can easily mask any view with any shape and path using UIBezierPath and CAShapeLayer. This provides us much more flexibility in laying out our subviews and making them as odd as possible.

Rounding corners

Any views’ corners can be rounded like so;

But, what if we wanted to round only two corners and let the other corners be squared? At this point UIBezierPath and CAShapeLayer come to the rescue!

First we need to create the path of our mask with the desired corners rounded.

Then we create the shape layer object with an adjusted frame to be set as mask layer of our view.

At this point, the only thing we need to do is to set the path of our mask layer.

Being a Core Animation framework class, CAShapeLayer's path takes a CGPath.

Now we have our mask to be applied. The only task left is to apply it! It's done so:

We have a brand new view whose top left and top right corners are rounded with a radius of 8.0.

Star

We want to our image view to be masked with a star. First create the star shaped bezier path, like so:

I used PaintCode 2 to create this bezier path. You can find the paint code drawing file here.

Also, I assumed that imageView is 256x256 points in size.

Then, create the layer and set its path:

And finally set imageView’s mask layer:

The result is:

]]>
<![CDATA[Hello, world!]]>Welcome to Objective Tidbits!

Objective Tidbits is a long time dream of mine. Here, I will be sharing my journey on iOS development. You will find useful information about solutions to common problems that we face every time, interesting bits of iOS, codes and pods that may help with a

]]>
https://www.pfleiderer-szkolenia.com/2015/02/27/hello-world/bed27c6c-1db8-4c98-9182-8ca56f29f797Fri, 27 Feb 2025 06:45:23 GMTWelcome to Objective Tidbits!

Objective Tidbits is a long time dream of mine. Here, I will be sharing my journey on iOS development. You will find useful information about solutions to common problems that we face every time, interesting bits of iOS, codes and pods that may help with a task, and anything about iOS development (and sometimes OS X development, I guess).

Who am I?

A little background information about me.

I'm a computer scientist who has specialised on Apple platforms and has been working on iOS development for a long time.

I've been working as an iOS developer professionally. Before that iOS was a playground for me in which I've developed apps sometimes just for fun, sometimes for school projects, and mostly to learn more and improve my skills and knowledge.

Currently I'm working at Doğuş Teknoloji as a senior iOS developer and running NSIstanbul Community with my friends here in Istanbul, Turkey.

So?

So you can follow me on twitter and github.

But more importantly, happy reading!

]]>