Coding Explorer Blog

Exploring how to code for iOS in Swift and Objective-C

  • Home
  • Apps
  • About
  • Contact

Supporting Dynamic Type for iOS7 Apps

Last updated on June 25, 2014

In a program I was working on, I decided to use Dynamic Type.  You can read about it here, but suffice it to say, it is a new way of handling text sizes in iOS7.  The user can set a value in their iOS device’s settings to set all text to be bigger or smaller than default, for any app that implements Dynamic Type.  This is a bit more advanced than my other posts, but it is surprisingly easy to do, so I thought I would write a post about what I learned.

Setup and using preferredFontForTextStyle

First off, you have to create an outlet for any label, textfield, or whatever you have that you want to dynamically change the text size of, so as to have a place to set the font.  The easiest way to do this is to use the assistant editor on your view, and command+drag your text control to the assistant editor (in the @interface area of your .m for a private outlet).  Once you release it will ask you a few questions, and the defaults are fine usually, so you just have to give it a name.

[Read more…]

Filed Under: Syntax

Objective-C Custom Initializers

Last updated on July 24, 2014

Let’s say you are programming a flashcard app.  In the model for these flashcards, you will have a flashcard object, and each flashcard has 2 strings as properties (one for the front of the card, and one for the back).  You could just alloc-init the card, and then set them later… but what use is a blank flashcard?  Why not only initialize a flashcard when those piece of data are provided?  That is what custom initializers are for.

Here is an example of making this flashcard class with its own custom initializer.

In FlashCard.h:

@interface FlashCard : NSObject

@property (strong, nonatomic) NSString *frontText;
@property (strong, nonatomic) NSString *backText;

- (instancetype)initWithFront:(NSString *)onFront back:(NSString *)onBack;

@end

In FlashCard.m:

#import "FlashCard.h" 

@implementation FlashCard

- (instancetype)initWithFront:(NSString *)onFront back:(NSString *)onBack
{
    if ((self = [super init])) {
        _frontText = onFront;
        _backText = onBack;
    }
    return self;
} 

@end

And that is pretty much all there is to it.  While it is not a lot of text, there are a few things that I had to look up a bit to understand what was going on in these statements, so I will go into more depth to explain some of the new things shown here.

[Read more…]

Filed Under: Syntax

Objective-C Syntax Primer 1: Methods

Last updated on June 25, 2014

Getting used to Objective-C Syntax

My previous experience with programming is mostly with languages similar to C in syntax.  So when I started to learn Objective-C, while it is still a subset of C, it diverged in a much different fashion to its brethren.  To give a little history lesson, Objective-C was began in the 1980s, as basically a combination of the languages “C” and “Smalltalk“.  Other C-derived languages include C++ (obviously) and Java.  Other Smalltalk-derived languages include Python and Ruby.  Since I am not particularly versed in Python or Ruby though, the aspects borrowed from that side of Objective-C’s family tree are currently a bit of a mystery to me, hence my trying to pass on what I’ve learned about the syntax.

[Read more…]

Filed Under: Objective-C, Syntax

  • « Previous Page
  • 1
  • 2

Subscribe to the Coding Explorer Newsletter

* indicates required

Follow Us

Facebooktwitterrss

Recent Posts

  • Error Handling in Swift
  • Creating and Modifying a URL in your Swift App
  • Watch Connectivity in Swift — Application Context
  • watchOS Hello World App in Swift
  • API Availability Checking in Swift

Categories

  • Class Reference
  • General
  • Interface Builder
  • My Apps
  • Objective-C
  • Swift
  • Syntax
  • Tutorial
  • Uncategorized

Archives

  • May 2016
  • March 2016
  • February 2016
  • December 2015
  • July 2015
  • June 2015
  • April 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • January 2014
  • November 2013
  • September 2013
  • August 2013
  • July 2013
  • Terms Of Use
  • Privacy Policy
  • Affiliate Disclaimer

Subscribe to the Coding Explorer Newsletter

* indicates required

Copyright © 2025 Wayne Media LLC · Powered by Genesis Framework · WordPress