Feeds:
Posts
Comentários

Handling dates in objective-c can be quite difficult if you don’t use the right tools.

And the best tools are for sure the NSDateComponents class. This class is available to both Mac and iOS development, and it makes handling dates much more simple.

Suppose that you need to get the month number of a date. If you don’t know NSDateComponents, a way to do that is create a NSDateFormatter and set the format only for the month and get a string that you could convert to a number. Simple  like that. Actually this is far from simple, and far from optimal and far from good programming practices.

Continuar Lendo »

Better Logging in iOS

I found this info in stackoverflow.com. The tip comes from Diederik Hoogenboom.

To better handle logging in your application you might want to use these macros:

#ifdef DEBUG

#   define DLog(fmt, …) NSLog((@“%s [Line %d] “ fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

#else

#   define DLog(…)

#endif

// ALog always displays output regardless of the DEBUG setting

#define ALog(fmt, …) NSLog((@“%s [Line %d] “ fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

I put these macros in a LOG.h file and add it to the .pch file located in the Other Sources folder in xCode, with an

#import “LOG.h”

To enable the DLog function just add the -DDEBUG flag in the “Other C Flags” option in your project’s configuration.

Just to remember you, the ALog will always print what you pass to it.

An example of a line from Dlog(@”Hello world”):

-[YourController yourMethod] [Line 100] Hello world

 

There are no accessors to the buttons and subviews of the UISearchBar public available by default, but we can access them thought the subviews method of the searchBar.

But why this is cool? Imagine you design a view and want a search bar on it. In order to go back from the search, or you need navigation bar with a back button, or you will need to create a back button for yourself in some place. But wait, the search bar can show a “cancel” button, can’t it? So you foward to use the cancel button and you realize that it comes disable until the user write something in the textfield. And we don’t want our users to need to type a letter in order to leave the search page. So with this trick, it’s pretty simple to enable the cancel button, even when the user typed nothing.

Put this code in the viewDidLoad method, or any place you prefer.

for (UIView *possibleButton in searchBar.subviews) {

if ([possibleButton isKindOfClass:[UIButton class]]){

UIButton *cancelButton = (UIButton*)possibleButton;

cancelButton.enabled = YES;

break;

}

}

Now you are done. Your cancel button will be available to the user even if he didn’t type any character.

Then yon can implement this method:

– (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar {

[self dismissModalViewControllerAnimated:YES];

}

and dismiss the view controller or anything you want. You can even change the text of the button with the method setTitle:ForState: of the button.

[cancelButton setTitle:@”Back” forState:UIControlStateNormal];

 

It’s pretty simple to use the camera (front, rear and camera albums) in an iphone application.

To get started just create an instance of UIImagePickerController with:

UIImagePickerController *picker = [[UIImagePickerController alloc] init];

After you need to decide the source of the image you want to capture. There are these possible values:

  • UIImagePickerControllerSourceTypeCamera – this will get the image from the camera.
  • UIImagePickerControllerSourceTypePhotoLibrary – this will open the album list of the photos app.
  • UIImagePickerControllerSourceTypeSavedPhotosAlbum – this will open the camera roll

you can specify which one you want with:

picker.sourceType = UIImagePickerControllerSourceTypeCamera;

You can also specify if you want the user to be able to edit the image (with cropping) with the property:

picker.allowsImageEditing = YES;

After you need to set a delegate to the controller. This delegate must implement the UIImagePickerControllerDelegate protocol at least this method:

  • – (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

this method will receive a dictionary containing some info about the chosen picture. The original image selected (without editing) will be under the key “UIImagePickerControllerOriginalImage”, the edited image (if you allowed the user to edit) will be under the key “UIImagePickerControllerEditedImage”. These properties are both instances of UIImage. You can even get the selected frame if the user edited the picture, with the property “UIImagePickerControllerCropRect”. This will be an instance of CGRect.

Finally to present the view controller, just invoke in your view controller:

[self presentModalViewController:picker animated:YES];

One last thing that is worth mentioning is that you can verify if your device has a camera before allowing him to use it.

To test if the user has a camera device just use this method (that returns a boolean):

[UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]

You can also query the user about the front camera with the parameter: UIImagePickerControllerCameraDeviceFront.

Knowing that a user does not even has a camera, may help you prevent a broken experience to the user.

Well, that’s all folks, at least for now.

Hope you enjoyed this tutorial.

 

After a couple of weeks it’s there on youtube the second version of the comic creator app.

This app will create all the comics that the Comic Reader app (for iPhone and iPad) will use.

To give a look at the reader app, just watch my old videos, as i didn’t update the reader for this release, it isn’t in the video.

It is avaliable now on youtube the video with the Mac application to create the comicbook.

As you can see this is still a prototype, and many things will change.

 

But even in this stage of prototyping the process to create comic books will be pretty simple, easy and fast.

I can imagine producing a full 22 pages comic in about 2~3 hours.

Stay tunned for updates in this application!

My comics iPad app prototype

I’m developing a new comics reader, much alike the one from comixology (marvel and DC). Now I already have almost the same effect from the comixology reader, but I’m planning to add some extra features.

The first other feature is a much more adaptable and interactive magazine store. Custom backgrounds, user defined backgrounds, also background music and music control, video and news subscriptions. For now it is already working the custom background.

Also to create the comics there is already a prototype app that make it so much easy, fast and simple to create te comic.

Hope you enjoyed this video. I will upload the magazine creator video soon.