Skip to main content

Posts

Showing posts from January, 2014

Giving a div (and a figure tag) about images in iBooks and Kindle

A standard way to centre images is to enclose them in div tags. As seen in this  Safari Online book on HTML 5. When we follow this to the letter with a  <p>text</p><div><img src="yourimage.jpg" /></div><p>text</p> structure in iBooks. Things work well on full-height images. But if we try and use the <div> as an opportunity to keep the image and caption together, then things take a turn for the worse. Doing this  <p>text</p><div><img  src="yourimage.jpg"  /> <p>caption text</p> </div><p>text</p> results in this: It seems that in the context of iBooks placing a paragraph within the image div grants iBooks permission to split an image across two pages. So what happens if we use the HTML 5 figure tag approach  <figure><img  src="yourimage.jpg"  /><figcaption><p>caption text</p> </figcaption> </figure>.  

Understanding document packages (Xcode/iOS)

Open Finder on OS X, navigate to a Pages file and right-click. You'll be given the option to 'Show Package Contents' and clicking this will allow you to navigate the contents as if it were a folder.    Now go to a folder, it doesn't matter which one. Change its name to add the extension .pages and instantly you'll see that it gains the Pages file icon. Pages won't be able to open this file, but it thinks it will. Next change the extension from .pages to .numbers and again you'll see the same behaviour but with a different icon. Right-click and as in the original example you'll be given the option to 'Show Package Contents'. Do this and all works as expected. Uniform type identifier (UTI) The above example works because document packages are simply folders. It is just that the apps that use document packages as their format register something called a uniform type identifier (UTI) in order for the system to recognise them and make th

Simple block methods in Xcode for iOS: The secret of the caret

The mysterious caret can be confusing to see in other people's code. But taking the simple example from Apple's code of a basic block (which is what the caret signifies) we can explain a little more clearly the meaning.     int (^Multiply)(int, int) = ^(int num1, int num2) {         return num1 * num2;     }; First to be understood, in the sample code, is that that the initial caret precedes the method name, next to which we have (int,int), which declares the number and type of variables accepted by the method. The second caret precedes the assignment of the variables to their given names for the purposes of the block. While at the very beginning of the line we have 'int', which is the thing returned by the method. Let's think about what this would look like if it were a regular method: -(int)Multiply:(int)num1 By:(int)num2 {      return num1 * num2; } And we'd then call the method in this way:    int result = [self Multiply:7 By:4] But th

Increase your AdSense revenue by blocking ads

Background Info If you use Google's  AdSense  in connection with your blog or website, then you'll probably be aware that it has an 'Allow & block ads' tab in its top menu. You might've used this already to block ads that might lower the sophistication of your site, or be unsuitable for your audience using the 'Sensitive Categories' submenu, but you can also block 'General Categories' as well and this post is about why you might want to consider doing this. Why would you want to block ads from the General Category? Next to each category in the table of 'General Categories' is the percentage of impressions for the month and the percentage of earnings. This will let you know how important each category of ad is to your audience. And logic tells us that we want to keep showing the ads that generate the most income and show less of the ones generating zero or very little income. What's the next step in raising my income? You ca

CGRect and CGGeometry: So much more than just a pretty frame

The objects and classes of iOS make it a powerful platform for programming apps. They also mean that there is an endless amount of documentation. This makes it easy to miss certain elements, especially best practice. To fill this gap comes the NYTimes Objective-C style guide on GitHub. I've already been inspired to write one blogpost  by this guide and this is a second. Glancing through the style guide, I happened upon the instructions for CGRect and measuring frame sizes . Now this is eye-opening stuff, because Apple's own documentation and code accesses frame sizes and positions using code like: - (void) viewDidLayoutSubviews { CGRect viewBounds = self.view.bounds; CGFloat bottomBarOffset = self.bottomLayoutGuide.length; } And yet, as the NYT guide tells us, Apple's  CGGeometry reference warns: All functions described in this reference that take CGRect data structures as inputs implicitly standardize those rectangles before calculating their results. For

Enable your iOS app to share files via iTunes and to open files sent from other apps ('Open In')

If you wish to enable your iOS app to share files via iTunes and/or to open files sent from other apps (using the 'Open In' functionality), then begin in both instances like this: (1) Click on the blue Project file icon within your Xcode project (2) select Info from the horizontal row of options Next, to enable files to be added and saved from your app via iTunes then do this (3) Expand 'Custom iOS Target Properties' (4) Right click on one of the rows (it doesn't matter which) and select Add Row (5) from the drop down list in the new row select ‘Application supports iTunes file sharing’ (6) Change the Value from NO to YES Or, to enable ‘Open in’ functionality, do the following (3) expand the Document Types option (4) insert the format Name and Types in the available form fields. The information needed to complete these fields can be found in Apple’s UTI (unique type identifier) reference document - for example to accept RTF files you would use RTF as t

Plugging the twitter time sink (with a text editor)

Once you begin to tweet on a regular basis, your brain becomes hardwired to send out pithy reports on your current activities and thinking. And if you work alone for periods of time then it becomes an enjoyable connection to others with similar outlooks and work as your own. This social contact after a while becomes something that you seek inside and outside your working hours, especially if those working hours are set by yourself and not others. While there’s no harm in a tweet and while twitter can be a source of knowledge and information, if you get caught up in a discussion or debate during your working hours it can put a great big hole in your productivity. Due to the risk of getting caught up in lengthy discussions on twitter based on a single tweet, I’ve tried many things to stop myself from tweeting when the impulse comes. Things like Pomodoro timers, allowing myself to tweet after a set amount of work, or re-chanelling the tweet energy into more productive areas. But all t