How do I associate file types with an iPhone application?

File type handling is new with iPhone OS 3.2, and is different than the already-existing custom URL schemes. You can register your application to handle particular document types, and any application that uses a document controller can hand off processing of these documents to your own application. For example, my application Molecules (for which the … Read more

Adjust UILabel height depending on the text

sizeWithFont constrainedToSize:lineBreakMode: is the method to use. An example of how to use it is below: //Calculate the expected size based on the font and linebreak mode of your label // FLT_MAX here simply means no constraint in height CGSize maximumLabelSize = CGSizeMake(296, FLT_MAX); CGSize expectedLabelSize = [yourString sizeWithFont:yourLabel.font constrainedToSize:maximumLabelSize lineBreakMode:yourLabel.lineBreakMode]; //adjust the label the … Read more

UILabel text margin [duplicate]

I solved this by subclassing UILabel and overriding drawTextInRect: like this: – (void)drawTextInRect:(CGRect)rect { UIEdgeInsets insets = {0, 5, 0, 5}; [super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)]; } Swift 3.1: override func drawText(in rect: CGRect) { let insets = UIEdgeInsets.init(top: 0, left: 5, bottom: 0, right: 5) super.drawText(in: UIEdgeInsetsInsetRect(rect, insets)) } Swift 4.2.1: override func drawText(in rect: CGRect) … Read more

NSString property: copy or retain?

For attributes whose type is an immutable value class that conforms to the NSCopying protocol, you almost always should specify copy in your @property declaration. Specifying retain is something you almost never want in such a situation. Here’s why you want to do that: NSMutableString *someName = [NSMutableString stringWithString:@”Chris”]; Person *p = [[[Person alloc] init] … Read more

iOS UIImagePickerController result image orientation after upload

A UIImage has a property imageOrientation, which instructs the UIImageView and other UIImage consumers to rotate the raw image data. There’s a good chance that this flag is being saved to the exif data in the uploaded jpeg image, but the program you use to view it is not honoring that flag. To rotate the … Read more

What are best practices that you use when writing Objective-C and Cocoa? [closed]

There are a few things I have started to do that I do not think are standard: 1) With the advent of properties, I no longer use “_” to prefix “private” class variables. After all, if a variable can be accessed by other classes shouldn’t there be a property for it? I always disliked the … Read more

UITableView – change section header color

This is an old question, but I think the answer needs to be updated. This method does not involve defining and creating your own custom view. In iOS 6 and up, you can easily change the background color and the text color by defining the -(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section section delegate method For example: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)