Posts

Showing posts with the label Objective-C

Debug logs

To enable debug logs in iOS application, add the following code in project PCH file. #if defined (DEBUGLOG) #define DebugLog( s, ... ) NSLog( @"%@", [NSString stringWithFormat:(s), ##__VA_ARGS__] ) #else #define DebugLog( s, ... ) #endif

Convert HEX code to RGB

To use hex code in UIColor, use the below macro. #define UIColorFromRGB(rgbValue) [UIColor \        colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \        green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \        blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] //Then use any Hex value self.view.backgroundColor = UIColorFromRGB(0xD2691E); 

Custom Message extension using Messages SDK - iMessage App store

Image
In our previous article , we discussed about creating custom sticker extension for our iMessage App store. We used images and using Messages SDK, we are able to create the custom extension for sticker. We also created a basic sticker extension in this article . Apple Messages SDK provides lot more features than just creating stickers. In today's article, we will create a custom message extension using Messages SDK and run them on iMessage app store. Before diving in to the project, lets look at the classes provided by Apple for implementation. MSMessagesAppViewController The MSMessagesAppViewController class acts as the principal view controller for Messages extensions. Use this class to manage your extension. MSMessageTemplateLayout The MSMessageTemplateLayout describes how an MSMessage object is presented in the transcript. The message template includes the Message extension’s icon, an image, video, or audio file, and a number of text elements (title, subtitle, captio...

Custom sticker extension using Messages SDK - iMessage App store

Image
In our previous article , we discussed about creating basic sticker extension for our iMessage App store. This step requires  to create imgages but no coding effort. Today, in this article we will discuss about creating a custom sticker extension and create stickers from the app. Before diving in to the project, let's have a quick glance about the new classes provided by Apple for implementation. MSMessagesAppViewController The MSMessagesAppViewController class acts as the principal view controller for Messages extensions. Use this class to manage your extension. MSStickerBrowserViewController Use the MSStickerBrowserViewController to present the standard sticker browser. This browser provides drag-and-drop functionality. The user can press and hold a sticker to peel it from the browser, then drag the sticker to any balloon in the transcript. The user can also tap stickers to add them to the Messages app’s input field. MSSticker A sticker for use in the Messages a...

Basic Sticker Extension using Messages SDK - iMessage App Extension

Image
Message App Extensions When bots and stickers are already available in most popular messaging apps, Apple has brought the native iMessage applications to the competition. Now developers can create app extensions, which can be part of existing apps or an individual extension which would be available in iMessage App Store. This iMessage App store is completely different from regular App Store. Using app extensions, Apple will allow its developers to create basic sticker packs, custom sticker applications and custom applications. Before we jump into the whole coding thing, let's have a quick look at app extensions. App Extension An app extension allows the developers to extend the custom functionality and contents beyond the application while the users are interacting with other apps or system. For example, a Today widget is a great extension to view the information even though the users are using any app. An app extension is a separate binary that runs inde...

Adding an UITextField to an UIAlertView in iPhone / iOS application

As we all know, UIAlertView is subclassed from UIView, its possible to add sub views to the alert view. Today, we will try to add an text field to UIAlertView. The code is attached below.     UIAlertView *alert = [[ UIAlertView alloc ] initWithTitle : @"See the text field below"     message : @"this gets covered!\n"   delegate : self cancelButtonTitle : @"Dismiss" otherButtonTitles : @"OK" , nil ];      alert. tag  = 1 000 ;            UITextField *_textField = [[ UITextField alloc ] initWithFrame : CGRectMake ( 12 , 45 , 260 , 25 )];     [_textField  setPlaceholder : @"Place holder text" ];     _textField. tag = 1 00 ;     _textField. clearButtonMode = UITextFieldViewModeWhileEditing ;     [_textField  setBackgroundColor :[ UIColor whiteColor ]];     [_textField  becomeFirstResponder ];     [alert a...

Integrating ZXing QR Code reader in iPhone / iOS applications

I spent a lot of time in integrating the QR code reader in iOS applications. I like to share you the steps and let you know the basic bugs that may happen during the integration process and how to debug that too :) Step 1  Download the latest code for QR code reader, zxing framework from github here . Step 2  Drag and drop the ZXingWidget.xcodeproj file to your project. Step 3  Copy the cpp folder from downloaded files (zxing-2.0) to your project. (The download files (zxing-2.0) depends upon the version that has been downloaded from github.) Step 4  Copy the iphone folder from downloaded files (zxing-2.0) to your project. (The download files (zxing-2.0) depends upon the version that has been downloaded from github.) Step 5 Add the following frameworks to your project.  Click on Project name -> Target -> Build Phases -> Link with libraries AudioToolbox.framework AddressBookUI.framework AddressBook.framework CoreVideo.framewor...

Transparent UIWebView in iPhone application

Hi Folks, Today, lets try to implement a transparent web view in our iphone application. Its quite simple and easy to use. 1. Set the background color of UIWebView to clear color. [myWebView setBackgroundColor:[UIColor clearColor]]; 2. Set the Opaque property of the UIWebView to NO.  myWebView.opaque = NO; 3.  Set the html page, body background property in style to transparent.  You can refer the above mentioned settings given in Apple Sample code, TransWeb .

Transparent UIWebView in iPhone application

Hi Folks, Today, lets try to implement a transparent web view in our iphone application. Its quite simple and easy to use. 1. Set the background color of UIWebView to clear color. [myWebView setBackgroundColor:[UIColor clearColor]]; 2. Set the Opaque property of the UIWebView to NO.  myWebView.opaque = NO; 3.  Set the html page, body background property in style to transparent.  You can refer the above mentioned settings given in Apple Sample code, TransWeb .

Cropping a part of UIImage in iPhone

To crop any part of an image in iPhone using Objective C, start with an UIImage object.    UIImage *image; Create a bitmap representation the image using the CGImageRef class.    CGImageRef imageReference = image.CGImage; Define the frame size for the part of image which should be cropped.    CGRect cropFrame = CGRectMake(10, 10, 50, 50); Now set the current context of UIGraphics    CGContextRef context = UIGraphicsGetCurrentContext(); Draw the image using the crop frame and imageReference using the current context.    CGContextDrawImage(UIGraphicsGetCurrentContext(), cropFrame, imageReference); Save the cropped image on a new UIImage object.    UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext(); After consolidating the above code to a single shot, it looks like,    UIImage *image;    CGImageRef imageReference = image.CGImage;  ...

Multiple line of text in UIPickerView

UIPickerView is a user interface component available from iOS 2.0 and above. The basic need of UIPickerView is to select any one option from the list of data that are loaded to the picker view. But, by default, only one line of text is allowed to be displayed in a UIPickerView . Today, we will try to add multi-line text to an UIPickerView . To do so, we need to implement the viewForComponent api.   - ( UIView  *)pickerView:( UIPickerView  *)pickerView viewForRow:( NSInteger )row forComponent:( NSInteger )component reusingView:( UIView  *)view; In that method, type cast the view parameter to an UILabel.    UILabel *pickerLabel = ( UILabel *)view; Update the frame size of the label.    CGRect frame = CGRectMake ( 0 , 0 , 265 , 40 );    pickerLabel = [[[ UILabel alloc ] initWithFrame :frame] autorelease ]; Set the properties of the label as per requirement.    [pickerLabel setTextAlig...

Play a video using an array of images in iPhone Objective C

When you want to play a video using an array of images in iPhone, you need to run the array of images in a loop and assign the images to the UIImageView. UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame]; for (int i = 0; i < [array count]; i++) {       imageView.image = (UIImage *) [array objectAtIndex: i]; }

Push notification count in iPhone application icon

If you want to show the number of push notifications received by your application from APNS, use the following code.   [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];  it will display 1 on the application icon. And, ONE MORE THING, You can also reset the application badge value by setting 0.   [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

Dynamic width and height for UILabel in iPhone

Having dynamic text to be displayed in application is a basic requirement. When you want to display the text, we can calculate the size of the dynamic text using the below code.   CGSize dynamicSize = [ sizeWithFont:[UIFont boldSystemFontOfSize:14.0] constrainedToSize:CGSizeMake(320, 999) lineBreakMode:UILineBreakModeWordWrap]; The font, constrainedToSize and lineBreakMode should be updated based on the requirement. Now, dynamic height value can be derived like,   NSLog(@"Dynamic Text Width: %f \nHeight: %f", dynamicSize.width, dynamicSize.height); And, to update the UILabel, use the dynamicSize.height value,   UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0,0,dynamicSize.width, dynamicSize.height)]; And, ONE MORE THING, Don't forget to set the numberOfLines property of UILabel to 0.