Ad

Our DNA is written in Swift
Jump

Archive for February 2010

Understanding UIFont

Have you ever really TRULY looked at the documentation of UIFont?

I had to, because I was looking for some metrics information that I could use to custom draw UILabels. And if you want to be independent of what font is set, then you have to get certain metrics, but the Apple SDK documentation of UIFont leaves a bit to desire.

When I asked which characters would be good representatives of a font, I was sent a link to this blog “celebrating the beauty of the ampersand”. Fine, an ampersand will be there as well…

Read more

How to deal with contracting customers who won't pay

If you do a bit of contracting besides or publishing your own apps then you will have to deal with a wide spectrum of human beings. Some appreciate every tiny tidbit of love you put into their apps. Some of the more entrepreneurial kind will constantly come with new ideas but always assume that those where part of the initial agreement.

I’ve had an encounter with an illustrious specimen of the second kind and so I thought it would be therapeutic for my hurt pride to ask the tweeting community about their opinion. Here are the responses for a view of what other iPhone developers generally think about this topic. I got a big number of responses which for the most part contain good food for thought.

Read more

DTSplashExtender

Typically you would use Default.png to show an empty user interface to reuse the subjective loading time of apps. This is especially true for productivity apps. Games are an example of the opposite. There you often see several splash screens with logos and copyright information. Between those extremes there are apps that use licensed materials and where it makes sense to briefly show such licensing information right at the start. The loading screen however is only showing for as long as the app needs to start up, which can be extremely short if the app is well coded and/or running on an iPhone 3GS.

So out of the need to display the loading screen”a bit longer” resulted revelopment of DTSplashExtender.

This new addition to my Dr. Touch Parts Store gives you this exact capability in a worry-free package. With this method you set a timeout of several seconds for which the Default.png is shown extra. You can have subsequent images that are faded to after the time has elapsed and show multiple pages with logos this way. When the show is over you dismiss the modal DTSplashExtender controller, your choice of flip, cross-dissolve or slide down.

There are delegate methods that you can hook into in your app delegate to perform certain actions when a certain page is showing. Additionally you can enable a feature where tapping the screen ends the show or fades to the next page right away. For example you could show a button to prompt the user to accept your licensing terms. Let me know if you have special requirements.

Here’s a quick demo:

DTCalendarView 2.0

When I saw the demo video of Billings Touch it hit me like a cold snowball: it also makes sense to use a calendar to select a date. Billings Touch shows you a nice big calendar view when you select a project due date. Shortly thereafter there was a discussion on date pickers on my favorite forum and the result of this also pointed towards the necessity of having a real calendar replace UIDatePicker.

So I sat down for 2 days straight to surgically remove the calendar-related parts from DTCalendarViewController and put those into their own class DTCalendarView. This enables you to use the view by itself. Also I put my secret sauce UIView+sliding into the project, as a free bonus. This category extension allows you to slide in any kind of UIView from the bottom of the screen. Together with DTCalendarView you get magic: a drop in UIDatePicker replacement!

Additionally to the above new features there where a couple of minor bug fixes and programmability improvements that will make your life as developer much easier. The update for DTCalendarViewController is free of charge for existing customers. To order your access and license go to the Dr. Touch’s Parts Store today!

Dr. Touch #012 – "iPad Aftermath"

A week after Apple announced the iPad the dust has begun to settle. Dr. Touch explores what the iPad really means for us developers.

This episode is brought to you by:

Dr. Touch’s Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support by Dr. Touch himself. Check it out today!

My Show Notes (aka Script) below the break…

Read more

Dr. Touch's Purchase Button

When you get around to adding In App Purchases (IAP) to your app you will find that Apple does not provide anything to help you with the UI. StoreKit only takes care of the buying backend. Therefore I sat down and spent many hours to construct a customizable purchase button to be the latest addition to the Dr. Touch Parts Store.

DTPurchaseButton

This is a button that has three states you need for In App Purchases: Neutral, Confirm and Purchased. For each of these states you can set a text and a title and the button does all the rest. It will send a message to your delegate when the button resizes so that you can move UI elements out of the way. It informs your app if a purchase should be made via StoreKit or whether it was cancelled. DTPurchase Button transmits an especially high value of your IAPs by  using a custom gloss finish.

Have a look at this video demonstration of the part in action:

Price: 100 EUR

You can order this part for use in your own projects via e-mail. See the terms and conditions at the bottom of my store page for the fine print.

Drawing Rounded Rectangles

Once you get deeper into coding iPhone apps you find that CoreGraphics starts to become a real friend. A friend who lacks in certain areas, because you will still have to piece together some shapes with the shape drawing functions that CG provides.

For sake of reusability you want to put the creation of distinct shapes into their own respective methods. You could make those into C functions like their CG brethren, but for our purposes objC-methods suffice.

This method creates a CGPath for a rounded rect inside the given rectangle with the given radius. We are alternating adding a straight line segment and then a corner by means of AddArcToPoint.

- (CGPathRef) newPathForRoundedRect:(CGRect)rect radius:(CGFloat)radius
{
	CGMutablePathRef retPath = CGPathCreateMutable();
 
	CGRect innerRect = CGRectInset(rect, radius, radius);
 
	CGFloat inside_right = innerRect.origin.x + innerRect.size.width;
	CGFloat outside_right = rect.origin.x + rect.size.width;
	CGFloat inside_bottom = innerRect.origin.y + innerRect.size.height;
	CGFloat outside_bottom = rect.origin.y + rect.size.height;
 
	CGFloat inside_top = innerRect.origin.y;
	CGFloat outside_top = rect.origin.y;
	CGFloat outside_left = rect.origin.x;
 
	CGPathMoveToPoint(retPath, NULL, innerRect.origin.x, outside_top);
 
	CGPathAddLineToPoint(retPath, NULL, inside_right, outside_top);
	CGPathAddArcToPoint(retPath, NULL, outside_right, outside_top, outside_right, inside_top, radius);
	CGPathAddLineToPoint(retPath, NULL, outside_right, inside_bottom);
	CGPathAddArcToPoint(retPath, NULL,  outside_right, outside_bottom, inside_right, outside_bottom, radius);
 
	CGPathAddLineToPoint(retPath, NULL, innerRect.origin.x, outside_bottom);
	CGPathAddArcToPoint(retPath, NULL,  outside_left, outside_bottom, outside_left, inside_bottom, radius);
	CGPathAddLineToPoint(retPath, NULL, outside_left, inside_top);
	CGPathAddArcToPoint(retPath, NULL,  outside_left, outside_top, innerRect.origin.x, outside_top, radius);
 
	CGPathCloseSubpath(retPath);
 
	return retPath;
}

The method has to be called new-something so that Build&Analyze does not tell you about a memory leak. Having the method name begin with new tells the static analyzer that this method is supposed to return something that the caller has to take care of releasing.

Now, if we want to use this method, then we can do so in any view’s drawRect:

- (void) drawRect:(CGRect)rect
{
	CGContextRef ctx = UIGraphicsGetCurrentContext();
 
	CGRect frame = self.bounds;
 
	CGPathRef roundedRectPath = [self newPathForRoundedRect:frame radius:5];
 
	[[UIColor blueColor] set];
 
	CGContextAddPath(ctx, roundedRectPath);
	CGContextFillPath(ctx);
 
	CGPathRelease(roundedRectPath);
}

Having the rounded rectangle shape as a path object allows us to reuse it several times. You could for example draw a gradient inside after having used the shape for clipping, then draw a border and also add a shadow. All from the same shape. At the end we just release it to clean up.