Change UITextField Placeholder Color

if ([textField respondsToSelector:@selector(setAttributedPlaceholder:)])
{
textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:textField.placeholder attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
}

Multiple methods named found with mismatched result parameter type or attributes

In one scenario, if the factory method that creates the object has return type “id” then the compiler will check the method signature in all the classes. If compiler find the same method signature in more than one class then it will raise the issue. So replace the return type “id” with “specific class name”.

Convert iPad xib to iPhone version

We can go with the following approach to get iPhone version of iPad xibs already exist in the project. With this approach we no need to create a new xib and manually add all the subviews.

1. Xcode recognises the iPhone version of a XIB if the suffix is ~iphone (lowercase only) and iPad version if its ~ipad. If no suffix exists then it will consider it as an iPhone version. Lets suffix all the existing xib names with ~ipad.

2. Duplicate all the xib files and open them in TextEditor and do the following.

change “com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB” to “com.apple.InterfaceBuilder3.CocoaTouch.XIB”
change “iOS.CocoaTouch.iPad” to “iOS.CocoaTouch”
change iPad size (width=”1024″ height=“768”) to iPhone size (width=“320″ height=“568″)

3. Add the xib to the project and open it on Xcode.

4. Select the root view and go to the attributes inspector.

5. Change the orientation to portrait and size to Retina 4-inch Full Screen.

6. Adjust the frame of all the subviews.

Make vertical scrollbar always visible in UIScrollView

Download : https://github.com/jaredsinclair/JTSScrollIndicator

JTSScrollIndicator.m

Add the following statements in the method initWithScrollView:

  • [_scrollView setShowsHorizontalScrollIndicator:NO];
  • [_scrollView setShowsVerticalScrollIndicator:NO];

Comment all the statements in the method hide:

JTSScrollIndicator.h

Added the following method declarations

  • - (void)show:(BOOL)animated;
  • + (BOOL)indicatorShouldBeVisibleForScrollView:(UIScrollView *)scrollView;

ViewController.h

#import “JTSScrollIndicator.h”
@property (strong, nonatomic) JTSScrollIndicator *indicator;

ViewController.m

- (void)viewDidLoad {
[super viewDidLoad];
self.indicator = [[JTSScrollIndicator alloc] initWithScrollView:scrollview];
self.indicator.backgroundColor = [UIColor colorWithRed:5.0/255.0 green:127.0/255.0 blue:231.0/255.0 alpha:1.0];
}

- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
scrollview.contentOffset = CGPointMake(0.0, 1.0);
[self.indicator show:YES];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[self.indicator scrollViewDidScroll:scrollView];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
[self.indicator scrollViewDidEndDragging:scrollView willDecelerate:decelerate];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
[self.indicator scrollViewDidEndDecelerating:scrollView];
}

- (void)scrollViewWillScrollToTop:(UIScrollView *)scrollView {
[self.indicator scrollViewWillScrollToTop:scrollView];
}

- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
[self.indicator scrollViewDidScrollToTop:scrollView];
}

Objective-C – How to use member variables in the categories.

.h

@interface UIView (ObjectTagAdditions)
@property (nonatomic, retain) id objectTag;
@end

.m

#import <objc/runtime.h>
static char const * const ObjectTagKey = "ObjectTag";

@implementation UIView (ObjectTagAdditions)
@dynamic objectTag;

- (id)objectTag {
    return objc_getAssociatedObject(self, &ObjectTagKey);
}

- (void)setObjectTag:(id)newObjectTag {
    objc_setAssociatedObject(self, &ObjectTagKey, newObjectTag, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

Cited from : http://oleb.net/blog/2011/05/faking-ivars-in-objc-categories-with-associative-references/

Convert yyyy-MM-ddTHH:mm:ss.SSSZ format to default timezone

- (NSDate *) localDateStringForISODateTimeString:(NSString *) anISOString

{
NSDateFormatter *isoDateFormatter = [[NSDateFormatter alloc] init];
[isoDateFormatter setDateFormat:@”yyyy-MM-dd’T’HH:mm:ss.SSS’Z'”];
[isoDateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@”UTC”]];

NSDateFormatter *userFormatter = [[NSDateFormatter alloc] init];
[userFormatter setDateFormat:@”yyyy-MM-dd HH:mm:ss”];

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@”yyyy-MM-dd HH:mm:ss”];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@”UTC”]];

NSDate *date = [isoDateFormatter dateFromString:anISOString];
return [dateFormatter dateFromString:[userFormatter stringFromDate:date]];
}

iOS orientation animation does not happen smoothly

If you apply any changes to the layer of underlying view.

for example,

shadowImageView.layer.masksToBounds = NO;
shadowImageView.layer.shadowOffset = CGSizeMake(-5, 0);
shadowImageView.layer.shadowOpacity = 1.0;

Follow

Get every new post delivered to your Inbox.

Join 357 other followers