Commit dcf57dbf authored by Achilles's avatar Achilles

import settings view controller from cruiser project.

parent dcbf94c6
......@@ -16,7 +16,7 @@ pod 'MBProgressHUD', '~> 0.9.1'
#pod 'SBJson', '~> 3.2'
#pod 'MMPickerView', '~> 0.0.1'
#pod 'SDWebImage', '~> 3.7.1'
pod 'SDWebImage', '~> 3.7.1'
#pod 'MBProgressHUD', '~> 0.8'
#pod 'SSKeychain', '~> 1.2'
......
This diff is collapsed.
//
// NSDate+FormatterAdditions.h
// JobTalk
//
// Created by Xummer on 14-5-16.
// Copyright (c) 2014年 BST. All rights reserved.
//
#import <Foundation/Foundation.h>
// https://github.com/samsoffes/sstoolkit/blob/master/SSToolkit/NSDate%2BSSToolkitAdditions.h
/**
Provides extensions to `NSDate` for various common tasks.
*/
@interface NSDate (FormatterAdditions)
///---------------
/// @name ISO 8601
///---------------
/**
Returns a new date represented by an ISO8601 string.
@param iso8601String An ISO8601 string
@return Date represented by the ISO8601 string
*/
+ (NSDate *)dateFromISO8601String:(NSString *)iso8601String;
/**
Returns a string representation of the receiver in ISO8601 format.
@return A string representation of the receiver in ISO8601 format.
*/
- (NSString *)ISO8601String;
/**
@param dateFormatter a date formatter, like @"%Y-%m-%dT%H:%M:%SZ".
@return A string representation of the receiver in dateFormatter.
*/
- (NSString *)stringWithFormatter:(NSString *)dateFormatter;
- (NSString *)chatAttachmentFormatterString;
- (NSString *)YMDHMSFormatterString;
- (NSString *)chatMsgFormatterString;
- (NSString *)localYMDString;
- (NSString *)briefTimeForTimeLine;
// yyyy-MM-dd HH:mm:ss
- (NSString *)httpParameterString;
// yymmddhhmmssSSS
- (NSString *)mobileIDDateString;
- (NSDate *)endOfTheDay;
///--------------------
/// @name Time In Words
///--------------------
/**
Returns a string representing the time interval from now in words (including seconds).
The strings produced by this method will be similar to produced by Twitter for iPhone or Tweetbot in the top right of
the tweet cells.
Internally, this does not use `timeInWordsFromTimeInterval:includingSeconds:`.
@return A string representing the time interval from now in words
*/
- (NSString *)briefTimeInWords;
/**
Returns a string representing the time interval from now in words (including seconds).
The strings produced by this method will be similar to produced by ActiveSupport's `time_ago_in_words` helper method.
@return A string representing the time interval from now in words
@see timeInWordsIncludingSeconds:
@see timeInWordsFromTimeInterval:includingSeconds:
*/
- (NSString *)timeInWords;
/**
Returns a string representing the time interval from now in words.
The strings produced by this method will be similar to produced by ActiveSupport's `time_ago_in_words` helper method.
@param includeSeconds `YES` if seconds should be included. `NO` if they should not.
@return A string representing the time interval from now in words
@see timeInWordsIncludingSeconds:
@see timeInWordsFromTimeInterval:includingSeconds:
*/
- (NSString *)timeInWordsIncludingSeconds:(BOOL)includeSeconds;
/**
Returns a string representing a time interval in words.
The strings produced by this method will be similar to produced by ActiveSupport's `time_ago_in_words` helper method.
@param intervalInSeconds The time interval to convert to a string
@param includeSeconds `YES` if seconds should be included. `NO` if they should not.
@return A string representing the time interval in words
@see timeInWords
@see timeInWordsIncludingSeconds:
*/
+ (NSString *)timeInWordsFromTimeInterval:(NSTimeInterval)intervalInSeconds includingSeconds:(BOOL)includeSeconds;
@end
@interface NSDate (DateFormatterAdditions)
- (NSString *)timeStampStr;
+ (NSString *)curTimeStamp;
@end
@interface NSNumber (DateFormatterAdditions)
- (NSDate *)dateValue;
- (NSDate *)overZeroDateValue;
@end
@interface NSString (DateFormatterAdditions)
- (NSTimeInterval)timeStamp;
- (NSDate *)dateValue;
- (NSDate *)overZeroDateValue;
@end
This diff is collapsed.
//
// NSMutableArray+SafeInsert.h
// Cruiser
//
// Created by Xummer on 4/10/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSMutableArray (SafeInsert)
- (void)safeAddObject:(id)object;
- (void)safeInsertObject:(id)object atIndex:(NSUInteger)index;
- (void)safeRemoveObjectAtIndex:(NSUInteger)index;
- (void)safeReplaceObjectAtIndex:(NSUInteger)index withObject:(id)object;
- (void)removeFirstObject;
@end
@interface NSMutableDictionary (SafeInsert)
- (void)safeSetObject:(id)object forKey:(id<NSCopying>)key;
- (void)safeRemoveObjectForKey:(id)key;
@end
@interface NSMutableSet (SafeInsert)
- (void)safeAddObject:(id)object;
- (void)safeRemoveObject:(id)object;
@end
@interface NSMutableString (SafeInsert)
- (void)safeAppendString:(NSString *)string;
@end
@interface NSArray (SafeFetch)
- (id)safeObjectAtIndex:(NSUInteger)index;
@end
\ No newline at end of file
//
// NSMutableArray+SafeInsert.m
// Cruiser
//
// Created by Xummer on 4/10/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "NSMutableArray+SafeInsert.h"
#pragma mark - NSMutableArray (SafeInsert)
@implementation NSMutableArray (SafeInsert)
- (void)safeAddObject:(id)object {
if (object) {
[self addObject:object];
}
}
- (void)safeInsertObject:(id)object atIndex:(NSUInteger)index {
if (index < self.count && object) {
[self insertObject:object atIndex:index];
}
}
- (void)safeRemoveObjectAtIndex:(NSUInteger)index {
if (index < self.count) {
[self removeObjectAtIndex:index];
}
}
- (void)safeReplaceObjectAtIndex:(NSUInteger)index withObject:(id)object {
if (index < self.count && object) {
[self replaceObjectAtIndex:index withObject:object];
}
}
- (void)removeFirstObject {
id firstObj = [self firstObject];
if (firstObj) {
[self removeObject:firstObj];
}
}
@end
#pragma mark - NSMutableDictionary (SafeInsert)
@implementation NSMutableDictionary (SafeInsert)
- (void)safeSetObject:(id)object forKey:(id <NSCopying>)key {
if (object) {
[self setObject:object forKey:key];
}
}
- (void)safeRemoveObjectForKey:(id)key {
[self removeObjectForKey:key];
}
@end
#pragma mark - NSMutableSet (SafeInsert)
@implementation NSMutableSet (SafeInsert)
- (void)safeAddObject:(id)object {
if (object) {
[self addObject:object];
}
}
- (void)safeRemoveObject:(id)object {
if (object) {
[self removeObject:object];
}
}
@end
#pragma mark - NSMutableString (SafeInsert)
@implementation NSMutableString (SafeInsert)
- (void)safeAppendString:(NSString *)string {
if ([string isKindOfClass:[NSString class]]) {
[self appendString:string];
}
}
@end
#pragma mark - NSArray (SafeFetch)
@implementation NSArray (SafeFetch)
- (id)safeObjectAtIndex:(NSUInteger)index {
@synchronized(self) {
if (index >= [self count]) return nil;
return [self objectAtIndex:index];
}
}
@end
//
// Created by kazuma.ukyo on 12/27/12.
//
// To change the template use AppCode | Preferences | File Templates.
//
#import <Foundation/Foundation.h>
// http://stackoverflow.com/questions/2060741/does-objective-c-use-short-circuit-evaluation
@interface NSNull (OVNatural)
- (void)forwardInvocation:(NSInvocation *)anInvocation;
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector;
@end
//
// Created by kazuma.ukyo on 12/27/12.
//
// To change the template use AppCode | Preferences | File Templates.
//
#import "NSNull+OVNatural.h"
@implementation NSNull (OVNatural)
- (void)forwardInvocation:(NSInvocation *)invocation
{
if ([self respondsToSelector:[invocation selector]]) {
[invocation invokeWithTarget:self];
}
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector
{
NSMethodSignature *sig = [[NSNull class] instanceMethodSignatureForSelector:selector];
if(sig == nil) {
sig = [NSMethodSignature signatureWithObjCTypes:"@^v^c"];
}
return sig;
}
@end
//
// NSString+TrimmingAdditions.h
// JobTalk
//
// Created by Xummer on 14-9-28.
// Copyright (c) 2014年 BST. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSString (TrimmingAdditions)
- (NSString *)stringByTrimmingLeadingCharactersInSet:(NSCharacterSet *)characterSet;
- (NSString *)stringByTrimmingLeadingWhitespaceAndNewlineCharacters;
- (NSString *)stringByTrimmingTrailingCharactersInSet:(NSCharacterSet *)characterSet;
- (NSString *)stringByTrimmingTrailingWhitespaceAndNewlineCharacters;
@end
@interface NSString (Segmentation)
- (NSString *)UserIDFromJidStr;
- (NSString *)JidStrWithUserID;
@end
@interface NSString (EncodeAndDecode)
- (NSString *)MD5String;
- (NSString *)uppercaseMD5String;
@end
@interface NSString (FileExt)
- (BOOL)extensionIsImageType;
@end
\ No newline at end of file
//
// NSString+TrimmingAdditions.m
// JobTalk
//
// Created by Xummer on 14-9-28.
// Copyright (c) 2014年 BST. All rights reserved.
//
#import "NSString+TrimmingAdditions.h"
@implementation NSString (TrimmingAdditions)
- (NSString *)stringByTrimmingLeadingCharactersInSet:(NSCharacterSet *)characterSet {
NSRange rangeOfFirstWantedCharacter = [self rangeOfCharacterFromSet:[characterSet invertedSet]];
if (rangeOfFirstWantedCharacter.location == NSNotFound) {
return @"";
}
return [self substringFromIndex:rangeOfFirstWantedCharacter.location];
}
- (NSString *)stringByTrimmingLeadingWhitespaceAndNewlineCharacters {
return [self stringByTrimmingLeadingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
- (NSString *)stringByTrimmingTrailingCharactersInSet:(NSCharacterSet *)characterSet {
NSRange rangeOfLastWantedCharacter = [self rangeOfCharacterFromSet:[characterSet invertedSet]
options:NSBackwardsSearch];
if (rangeOfLastWantedCharacter.location == NSNotFound) {
return @"";
}
return [self substringToIndex:rangeOfLastWantedCharacter.location+1]; // non-inclusive
}
- (NSString *)stringByTrimmingTrailingWhitespaceAndNewlineCharacters {
return [self stringByTrimmingTrailingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
@end
#import <CommonCrypto/CommonDigest.h>
@implementation NSString (EncodeAndDecode)
- (NSString *)MD5String {
// Create pointer to the string as UTF8
const char *ptr = [self UTF8String];
// Create byte array of unsigned chars
unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];
// Create 16 byte MD5 hash value, store in buffer
CC_MD5(ptr, (CC_LONG)strlen(ptr), md5Buffer);
// Convert MD5 value in the buffer to NSString of hex values
NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
[output appendFormat:@"%02x",md5Buffer[i]];
return output;
}
- (NSString *)uppercaseMD5String {
// return [[self MD5String] uppercaseString];
return [self MD5String];
}
@end
@implementation NSString (FileExt)
- (BOOL)extensionIsImageType {
NSString *ext = [[self pathExtension] lowercaseString];
if ([ext isEqualToString:@"jpeg"] ||
[ext isEqualToString:@"jpg"] ||
[ext isEqualToString:@"png"] ) {
return YES;
}
return NO;
}
@end
\ No newline at end of file
//
// UIApplication+CheckFirstRun.h
// Cruiser
//
// Created by Xummer on 3/26/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIApplication (CheckFirstRun)
- (BOOL)isFirstRun;
- (BOOL)isFirstRunCurrentVersion;
- (void)setFirstRun;
- (void)setNotFirstRun;
- (float)version;
@end
//
// UIApplication+CheckFirstRun.m
// Cruiser
//
// Created by Xummer on 3/26/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "UIApplication+CheckFirstRun.h"
@implementation UIApplication (CheckFirstRun)
- (BOOL)isFirstRun{
return [[NSUserDefaults standardUserDefaults] valueForKey:@"version"] == nil;
}
- (BOOL)isFirstRunCurrentVersion {
if ([self isFirstRun]) {
return YES;
}
else {
return [[NSUserDefaults standardUserDefaults] floatForKey:@"version"] == [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] floatValue];
}
}
- (void)setFirstRun {
[[NSUserDefaults standardUserDefaults] setFloat:-1 forKey:@"version"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (void)setNotFirstRun {
[[NSUserDefaults standardUserDefaults] setFloat:[self version] forKey:@"version"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (float)version {
return [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] floatValue];
}
@end
//
// UIColor+Helper.h
// SAO
//
// Created by Xummer on 14-3-20.
// Copyright (c) 2014年 Xummer. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIColor (Helper)
// Input float color value without /255.0f
+ (UIColor *)colorWithR:(CGFloat)red g:(CGFloat)green b:(CGFloat)blue a:(CGFloat)alpha;
+ (UIColor *)colorWithW:(CGFloat)white a:(CGFloat)alpha;
/**
colorFromHex
@param rgbValue please input like 0xFF1226
@returns color from rgbValue
*/
+ (UIColor *)colorFromHex:(int32_t)rgbValue;
@end
//
// UIColor+Helper.m
// SAO
//
// Created by Xummer on 14-3-20.
// Copyright (c) 2014年 Xummer. All rights reserved.
//
#import "UIColor+Helper.h"
@implementation UIColor (Helper)
+ (UIColor *)colorWithR:(CGFloat)red g:(CGFloat)green b:(CGFloat)blue a:(CGFloat)alpha {
return [UIColor colorWithRed:red/255.0f green:green/255.0f blue:blue/255.0f alpha:alpha];
}
+ (UIColor *)colorWithW:(CGFloat)white a:(CGFloat)alpha {
return [UIColor colorWithWhite:white/255.0f alpha:alpha];
}
+ (UIColor *)colorFromHex:(int32_t)rgbValue {
return [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0
green:((float)((rgbValue & 0xFF00) >> 8))/255.0
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0];
}
@end
//
// UIFont+Custom.h
// SAO
//
// Created by Xummer on 14-3-20.
// Copyright (c) 2014年 Xummer. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIFont (Custom)
+ (UIFont *)customFontOfSize:(CGFloat)fontSize;
+ (UIFont *)boldCustomFontOfSize:(CGFloat)fontSize;
@end
//
// UIFont+Custom.m
// SAO
//
// Created by Xummer on 14-3-20.
// Copyright (c) 2014年 Xummer. All rights reserved.
//
#import "UIFont+Custom.h"
@implementation UIFont (Custom)
+ (UIFont *)customFontOfSize:(CGFloat)fontSize {
return [UIFont fontWithName:@"SAOUITT-Regular" size:fontSize];
}
+ (UIFont *)boldCustomFontOfSize:(CGFloat)fontSize {
return [UIFont fontWithName:@"SAOUITT-Bold" size:fontSize];
}
@end
//
// UIImage+Helper.h
// CXA
//
// Created by Xummer on 14-3-3.
// Copyright (c) 2014年 Xummer. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIImage (Helper)
+ (UIImage *)getThumbnailImage:(UIImage *)image withMaxLen:(CGFloat)maxLen;
- (UIImage *)thumbnailWithMaxLen:(CGFloat)maxLen;
- (UIImage *)imageWithTintColor:(UIColor *)tintColor;
- (UIImage *)imageWithGradientTintColor:(UIColor *)tintColor;
- (UIImage *)imageWithTintColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode;
@end
@interface UIImage (Color)
+ (UIImage *)imageWithColor:(UIColor *)color;
+ (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size;
+ (UIImage *)imageWithColor:(UIColor *)color andRect:(CGRect)rect;
- (UIImage *)greyScaleImage;
@end
//
// UIImage+Helper.m
// CXA
//
// Created by Xummer on 14-3-3.
// Copyright (c) 2014年 Xummer. All rights reserved.
//
#import "UIImage+Helper.h"
@implementation UIImage (Helper)
// if newImage's width or heigth < 1, image will be cliped
+ (UIImage *)getThumbnailImage:(UIImage *)image withMaxLen:(CGFloat)maxLen
{
CGFloat imageMaxLen, imageMinLen;
BOOL widthIsLarger = image.size.width > image.size.height;
if (widthIsLarger) {
imageMaxLen = image.size.width;
imageMinLen = image.size.height;
}
else {
imageMaxLen = image.size.height;
imageMinLen = image.size.width;
}
if (imageMaxLen > maxLen) {
CGFloat scaleFloat = maxLen/imageMaxLen;
CGFloat newImgMinL = imageMinLen * scaleFloat;
CGSize size;
if (newImgMinL < 1) {
scaleFloat = 1/imageMinLen;
if (widthIsLarger) {
size = CGSizeMake(maxLen, image.size.height * scaleFloat);
}
else {
size = CGSizeMake(image.size.width * scaleFloat, maxLen);
}
}
else {
size = CGSizeMake(image.size.width * scaleFloat,
image.size.height * scaleFloat);
}
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformScale(transform, scaleFloat, scaleFloat);
CGContextConcatCTM(context, transform);
// Draw the image into the transformed context and return the image
[image drawAtPoint:CGPointMake(0.0f, 0.0f)];
UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newimg;
}
else{
return image;
}
}
- (UIImage *)thumbnailWithMaxLen:(CGFloat)maxLen {
return [[self class] getThumbnailImage:self withMaxLen:maxLen];
}
- (UIImage *)imageWithTintColor:(UIColor *)tintColor {
return [self imageWithTintColor:tintColor blendMode:kCGBlendModeDestinationIn];
}
- (UIImage *)imageWithGradientTintColor:(UIColor *)tintColor {
return [self imageWithTintColor:tintColor blendMode:kCGBlendModeOverlay];
}
- (UIImage *)imageWithTintColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode
{
//We want to keep alpha, set opaque to NO; Use 0.0f for scale to use the scale factor of the device’s main screen.
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f);
[tintColor setFill];
CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height);
UIRectFill(bounds);
//Draw the tinted image in context
[self drawInRect:bounds blendMode:blendMode alpha:1.0f];
if (blendMode != kCGBlendModeDestinationIn) {
[self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f];
}
UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return tintedImage;
}
@end
@implementation UIImage (Color)
typedef enum {
ALPHA = 0,
BLUE = 1,
GREEN = 2,
RED = 3
} PIXELS;
+ (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f,0.0f,1.0f,1.0f);
return [[self class] imageWithColor:color andRect:rect];
}
+ (UIImage *)imageWithColor:(UIColor *)color andRect:(CGRect)rect {
UIGraphicsBeginImageContext(rect.size);
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context,[color CGColor]);
CGContextFillRect(context, rect);
UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
+ (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size {
return [[self class] imageWithColor:color andRect:(CGRect){
.origin = CGPointZero,
.size = size
}];
}
- (UIImage *)greyScaleImage {
CGSize size = [self size];
int width = size.width;
int height = size.height;
// the pixels will be painted to this array
uint32_t *pixels = (uint32_t *) malloc(width * height * sizeof(uint32_t));
// clear the pixels so any transparency is preserved
memset(pixels, 0, width * height * sizeof(uint32_t));
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
// create a context with RGBA pixels
CGContextRef context = CGBitmapContextCreate(pixels, width, height, 8, width * sizeof(uint32_t), colorSpace,
kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast);
// paint the bitmap to our context which will fill in the pixels array
CGContextDrawImage(context, CGRectMake(0, 0, width, height), [self CGImage]);
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
uint8_t *rgbaPixel = (uint8_t *) &pixels[y * width + x];
// convert to grayscale using recommended method: http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
uint32_t gray = 0.3 * rgbaPixel[RED] + 0.59 * rgbaPixel[GREEN] + 0.11 * rgbaPixel[BLUE];
// set the pixels to gray
rgbaPixel[RED] = gray;
rgbaPixel[GREEN] = gray;
rgbaPixel[BLUE] = gray;
}
}
// create a new CGImageRef from our context with the modified pixels
CGImageRef image = CGBitmapContextCreateImage(context);
// we're done with the context, color space, and pixels
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
free(pixels);
// make a new UIImage to return
UIImage *resultUIImage = [UIImage imageWithCGImage:image];
// we're done with image now too
CGImageRelease(image);
return resultUIImage;
}
@end
//
// UILabel+SizeCalculate.h
//
//
// Created by Xummer on 14-2-19.
// Copyright (c) 2014年 Xummer. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UILabel (SizeCalculate)
+ (CGFloat)getLabelWidth:(UILabel *)label;
+ (CGFloat)getLabelHeight:(UILabel *)label;
+ (CGSize)getLabelSize:(UILabel *)label;
+ (CGSize)getSizeWithText:(NSString *)text font:(UIFont *)font andSize:(CGSize)size;
+ (CGSize)getSizeWithText:(NSString *)text font:(UIFont *)font andWidth:(CGFloat)width;
+ (CGFloat)getHeightWithText:(NSString *)text font:(UIFont *)font andWidth:(CGFloat)width;
+ (CGFloat)getWidthWithText:(NSString *)text font:(UIFont *)font andHeight:(CGFloat)height;
- (CGFloat)calculateWidth;
- (CGFloat)calculateHeight;
- (CGSize)calculateSize;
@end
//
// UILabel+SizeCalculate.m
//
//
// Created by Xummer on 14-2-19.
// Copyright (c) 2014年 Xummer. All rights reserved.
//
#import "UILabel+SizeCalculate.h"
#import "IBTConstants.h"
@implementation UILabel (SizeCalculate)
+ (CGSize)getSizeWithText:(NSString *)text font:(UIFont *)font andSize:(CGSize)size {
CGSize expectedLabelSize = CGSizeZero;
if (!font || !text ) {
return expectedLabelSize;
}
if (IBT_IOS7_OR_LATER) {
NSDictionary *stringAttributes = @{ NSFontAttributeName : font };
expectedLabelSize =
[text boundingRectWithSize:size
options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin
attributes:stringAttributes
context:nil].size;
}
else {
expectedLabelSize =
[text sizeWithFont:font
constrainedToSize:size
lineBreakMode:NSLineBreakByWordWrapping];
}
return expectedLabelSize;
}
+ (CGSize)getSizeWithText:(NSString *)text font:(UIFont *)font andWidth:(CGFloat)width {
return [[self class] getSizeWithText:text
font:font
andSize:CGSizeMake(width, MAXFLOAT)];
}
+ (CGFloat)getWidthWithText:(NSString *)text font:(UIFont *)font andHeight:(CGFloat)height {
CGSize expectedLabelSize = CGSizeZero;
if (IBT_IOS7_OR_LATER) {
NSDictionary *stringAttributes = @{ NSFontAttributeName : font };
expectedLabelSize =
[text boundingRectWithSize:CGSizeMake(MAXFLOAT, height)
options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin
attributes:stringAttributes
context:nil].size;
}
else {
expectedLabelSize =
[text sizeWithFont:font
constrainedToSize:CGSizeMake(MAXFLOAT, height)
lineBreakMode:NSLineBreakByWordWrapping];
}
return ceil(expectedLabelSize.width);
}
+ (CGFloat)getLabelWidth:(UILabel *)label {
return [[self class] getWidthWithText:label.text
font:label.font
andHeight:CGRectGetHeight(label.frame)];
}
+ (CGFloat)getLabelHeight:(UILabel *)label {
return [[self class] getHeightWithText:label.text
font:label.font
andWidth:label.frame.size.width];
}
+ (CGSize)getLabelSize:(UILabel *)label {
return [[self class] getSizeWithText:label.text
font:label.font
andWidth:CGRectGetWidth(label.frame)];
}
+ (CGFloat)getHeightWithText:(NSString *)text font:(UIFont *)font andWidth:(CGFloat)width {
return ceil([[self class] getSizeWithText:text
font:font
andWidth:width].height);
}
- (CGFloat)calculateWidth {
return [[self class] getLabelWidth:self];
}
- (CGFloat)calculateHeight {
return [[self class] getLabelHeight:self];
}
- (CGSize)calculateSize {
return [[self class] getLabelSize:self];
}
@end
//
// UIResponder+FirstResponder.h
// JobTalk
//
// Created by Xummer on 14/12/18.
// Copyright (c) 2014年 BST. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIResponder (FirstResponder)
+ (id)currentFirstResponder;
@end
//
// UIResponder+FirstResponder.m
// JobTalk
//
// Created by Xummer on 14/12/18.
// Copyright (c) 2014年 BST. All rights reserved.
//
#import "UIResponder+FirstResponder.h"
static __weak id currentFirstResponder;
@implementation UIResponder (FirstResponder)
+ (id)currentFirstResponder {
currentFirstResponder = nil;
[[UIApplication sharedApplication] sendAction:@selector(findFirstResponder:) to:nil from:nil forEvent:nil];
return currentFirstResponder;
}
- (void)findFirstResponder:(id)sender {
currentFirstResponder = self;
}
@end
//
// UIScrollView+Content.h
// Cruiser
//
// Created by Xummer on 15/6/8.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIScrollView (Content)
- (void)setContentInsetTop:(CGFloat)top andBottom:(CGFloat)bottom;
@end
//
// UIScrollView+Content.m
// Cruiser
//
// Created by Xummer on 15/6/8.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "UIScrollView+Content.h"
@implementation UIScrollView (Content)
- (void)setContentInsetTop:(CGFloat)top andBottom:(CGFloat)bottom {
self.contentInset = UIEdgeInsetsMake(top, 0, bottom, 0);
self.scrollIndicatorInsets = self.contentInset;
}
@end
//
// UITabBarItem+Universal.h
// AceMTer
//
// Created by Xummer on 2/27/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UITabBarItem (Universal)
+ (instancetype)itemWithTitle:(NSString *)title
image:(UIImage *)image
selectedImage:(UIImage *)selectedImage;
@end
//
// UITabBarItem+Universal.m
// AceMTer
//
// Created by Xummer on 2/27/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "UITabBarItem+Universal.h"
#import "IBTUIKit.h"
@implementation UITabBarItem (Universal)
+ (instancetype)itemWithTitle:(NSString *)title
image:(UIImage *)image
selectedImage:(UIImage *)selectedImage
{
UITabBarItem *tabBarItem = nil;
if (IBT_IOS7_OR_LATER) {
tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:image selectedImage:selectedImage];
}
else {
tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:nil tag:0];
[tabBarItem setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:image];
}
return tabBarItem;
}
@end
//
// UITableViewCell+Helper.h
// CXA
//
// Created by Xummer on 14-3-19.
// Copyright (c) 2014年 Xummer. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UITableViewCell (Helper)
+ (UINib *)nib;
+ (id)cellFromNib;
+ (CGFloat)getCellHeight;
+ (NSString *)reuseIdentifier;
@end
//
// UITableViewCell+Helper.m
// CXA
//
// Created by Xummer on 14-3-19.
// Copyright (c) 2014年 Xummer. All rights reserved.
//
#import "UITableViewCell+Helper.h"
@implementation UITableViewCell (Helper)
+ (UINib *)nib {
return [UINib nibWithNibName:NSStringFromClass([self class]) bundle:nil];
}
+ (id)cellFromNib {
NSArray *array =
[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class])
owner:self
options:nil];
return [array firstObject];
}
+ (CGFloat)getCellHeight {
UITableViewCell *cell = [[self class] cellFromNib];
return CGRectGetHeight(cell.frame);
}
+ (NSString *)reuseIdentifier {
return NSStringFromClass([self class]);
}
@end
//
// UIView+FindUIViewController.h
// JobTalk
//
// Created by Xummer on 1/20/15.
// Copyright (c) 2015 BST. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface UIView (FindUIViewController)
- (UIViewController *)firstAvailableUIViewController;
- (id)traverseResponderChainForUIViewController;
@end
@interface UIView (Extend)
- (NSArray *)subviewsWithClass:(Class)aClass;
- (id)viewWithClass:(Class)aClass;
- (void)removeSubViewWithClass:(Class)aClass;
- (void)removeSubViewWithTag:(NSInteger)tag;
- (void)removeAllSubViews;
- (void)autoresizingWithStrechFullSize;
- (void)autoresizingWithVerticalCenter;
- (void)autoresizingWithHorizontalCenter;
@end
//
// UIView+FindUIViewController.m
// JobTalk
//
// Created by Xummer on 1/20/15.
// Copyright (c) 2015 BST. All rights reserved.
//
#import "UIView+FindUIViewController.h"
@implementation UIView (FindUIViewController)
- (UIViewController *)firstAvailableUIViewController {
// convenience function for casting and to "mask" the recursive function
return (UIViewController *)[self traverseResponderChainForUIViewController];
}
- (id)traverseResponderChainForUIViewController {
id nextResponder = [self nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
return nextResponder;
}
else if ([nextResponder isKindOfClass:[UIView class]]) {
return [nextResponder traverseResponderChainForUIViewController];
}
else {
return nil;
}
}
@end
@implementation UIView (Extend)
- (NSArray *)subviewsWithClass:(Class)aClass {
NSMutableArray *arrTmp = [NSMutableArray array];
for (UIView *view in self.subviews) {
if ([view isKindOfClass:aClass]) {
[arrTmp addObject:view];
}
}
return [arrTmp count] > 0 ? arrTmp : nil;
}
- (id)viewWithClass:(Class)aClass {
__block id machedView = nil;
[self.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:aClass]) {
machedView = obj;
*stop = YES;
}
}];
return machedView;
}
- (void)removeSubViewWithClass:(Class)aClass {
[[self viewWithClass:aClass] removeFromSuperview];
}
- (void)removeSubViewWithTag:(NSInteger)tag {
[[self viewWithTag:tag] removeFromSuperview];
}
- (void)removeAllSubViews {
[self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
}
- (void)autoresizingWithStrechFullSize {
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
- (void)autoresizingWithVerticalCenter {
self.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
}
- (void)autoresizingWithHorizontalCenter {
self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
}
@end
//
// UIView+ViewFrameGeometry.h
// IBTTableViewKit
//
// Created by Xummer on 15/1/9.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIView (ViewFrameGeometry)
@property (assign) CGFloat x;
@property (assign) CGFloat y;
@property (assign) CGFloat width;
@property (assign) CGFloat height;
@property (assign) CGSize size;
@property (assign) CGPoint origin;
@property (assign) CGFloat left;
@property (assign) CGFloat right;
@property (assign) CGFloat top;
@property (assign) CGFloat bottom;
@property (readonly, assign) CGPoint topRight;
@property (readonly, assign) CGPoint bottomRight;
@property (readonly, assign) CGPoint bottomLeft;
//- (void)frameIntegral;
//- (void)ceilAllSubviews;
//- (void)fitTheSubviews;
- (void)fitInSize:(CGSize)aSize;
- (void)scaleBy:(CGFloat)fScaleFactor;
- (void)moveBy:(CGPoint)pDelta;
- (CGSize)widthLimitedSizeThatFits:(CGSize)size;
- (CGSize)heightLimitedSizeThatFits:(CGSize)size;
@end
//
// UIView+ViewFrameGeometry.m
// IBTTableViewKit
//
// Created by Xummer on 15/1/9.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "UIView+ViewFrameGeometry.h"
@implementation UIView (ViewFrameGeometry)
- (CGFloat) x {
return self.frame.origin.x;
}
- (void) setX:(CGFloat)x {
CGRect nframe = self.frame;
nframe.origin.x = x;
self.frame = nframe;
}
- (CGFloat) y {
return self.frame.origin.y;
}
- (void) setY:(CGFloat)y {
CGRect nframe = self.frame;
nframe.origin.y = y;
self.frame = nframe;
}
// Retrieve and set height, width
- (CGFloat) width {
return self.frame.size.width;
}
- (void) setWidth:(CGFloat)width {
CGRect nframe = self.frame;
nframe.size.width = width;
self.frame = nframe;
}
- (CGFloat) height {
return self.frame.size.height;
}
- (void) setHeight:(CGFloat)height {
CGRect nframe = self.frame;
nframe.size.height = height;
self.frame = nframe;
}
// Retrieve and set the origin, size
- (CGPoint) origin {
return self.frame.origin;
}
- (void) setOrigin:(CGPoint)aPoint {
CGRect nframe = self.frame;
nframe.origin = aPoint;
self.frame = nframe;
}
- (CGSize) size {
return self.frame.size;
}
- (void) setSize:(CGSize)aSize {
CGRect nframe = self.frame;
nframe.size = aSize;
self.frame = nframe;
}
// Retrieve and set top, bottom, left, right
- (CGFloat) left {
return self.x;
}
- (void) setLeft:(CGFloat)left {
self.x = left;
}
- (CGFloat) right {
return CGRectGetMaxX(self.frame);
}
- (void) setRight:(CGFloat)right {
self.x = right - self.width;
}
- (CGFloat) top {
return self.y;
}
- (void) setTop:(CGFloat)top {
self.y = top;
}
- (CGFloat) bottom {
return CGRectGetMaxY(self.frame);
}
- (void) setBottom:(CGFloat)bottom {
self.y = bottom - self.height;
}
// Query other frame locations
- (CGPoint) topRight {
return CGPointMake(self.right, self.top);
}
- (CGPoint) bottomRight {
return CGPointMake(self.right, self.bottom);
}
- (CGPoint) bottomLeft {
return CGPointMake(self.left, self.bottom);
}
// Move via offset
- (void) moveBy:(CGPoint)delta
{
CGPoint nCenter = self.center;
nCenter.x += delta.x;
nCenter.y += delta.y;
self.center = nCenter;
}
// Scaling
- (void) scaleBy:(CGFloat)scaleFactor {
CGRect nframe = self.frame;
nframe.size.width *= scaleFactor;
nframe.size.height *= scaleFactor;
self.frame = nframe;
}
// Ensure that both dimensions fit within the given size by scaling down
- (void) fitInSize:(CGSize)aSize {
CGFloat scale;
CGRect nframe = self.frame;
if (nframe.size.height && (nframe.size.height > aSize.height)) {
scale = aSize.height / nframe.size.height;
nframe.size.width *= scale;
nframe.size.height *= scale;
}
if (nframe.size.width && (nframe.size.width >= aSize.width)) {
scale = aSize.width / nframe.size.width;
nframe.size.width *= scale;
nframe.size.height *= scale;
}
self.frame = nframe;
}
- (CGSize) widthLimitedSizeThatFits:(CGSize)size {
CGSize mSize = [self sizeThatFits:size];
if (mSize.width > size.width) {
mSize.width = size.width;
}
return mSize;
}
- (CGSize) heightLimitedSizeThatFits:(CGSize)size {
CGSize mSize = [self sizeThatFits:size];
if (mSize.height > size.height) {
mSize.height = size.height;
}
return mSize;
}
@end
//
// UIViewController+LogicController.h
// Cruiser
//
// Created by Xummer on 15/4/3.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIViewController (LogicController)
- (UIImage *)getViewControllerImage:(CGSize)imageSize;
// Navigation
- (BOOL)isCurrentViewController;
- (void)onBackButtonClicked;
- (UIViewController *)getViewControllerAtIndex:(NSInteger)iIndex;
- (void)PushViewController:(UIViewController *)viewController animated:(BOOL)bAnimated;
- (UIViewController *)PopViewControllerAnimated:(BOOL)bAnimated;
- (NSArray *)PopToViewController:(UIViewController *)viewController animated:(BOOL)bAnimated;
- (NSArray *)PopToRootViewControllerAnimated:(BOOL)bAnimated;
- (NSArray *)PopToViewControllerWithClass:(Class)vcClass animated:(BOOL)bAnimated;
- (NSArray *)PopToViewControllerAtIndex:(NSInteger)index animated:(BOOL)bAnimated;
@end
@interface UIViewController (ModalView)
//- (void)releasePopoverController:(id)controller;
//- (void)popoverControllerDidDismissPopover:(id)popoverController;
- (void)DismissMyselfAnimated:(BOOL)bAnimated;
- (void)DismissModalViewControllerAnimated:(BOOL)bAnimated;
- (void)PresentModalViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)bAnimated;
- (void)PresentViewControllerInNewNavigation:(UIViewController *)viewControllerToPresent animated:(BOOL)bAnimated completion:(void (^)(void))completion;
@end
@interface UIViewController (margin)
- (void)setLeftBarButtonItem:(UIBarButtonItem *)item;
- (UIBarButtonItem *)leftBarButtonItem;
- (void)setRightBarButtonItem:(UIBarButtonItem *)item;
- (UIBarButtonItem *)rightBarButtonItem;
- (void)setLeftBarButtonItems:(NSArray *)items;
- (void)setRightBarButtonItems:(NSArray *)items;
- (UIBarButtonItem *)addLeftBarBtnItemWithName:(NSString *)btnName action:(SEL)selector;
- (UIBarButtonItem *)addRightBarBtnItemWithName:(NSString *)btnName action:(SEL)selector;
@end
//
// UIViewController+LogicController.m
// Cruiser
//
// Created by Xummer on 15/4/3.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "UIViewController+LogicController.h"
@implementation UINavigationController (ShouldPopOnBackButton)
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item {
if([self.viewControllers count] < [navigationBar.items count]) {
return YES;
}
UIViewController* vc = [self topViewController];
if([vc respondsToSelector:@selector(onBackButtonClicked)]) {
[vc onBackButtonClicked];
}
else {
dispatch_async(dispatch_get_main_queue(), ^{
[self popViewControllerAnimated:YES];
});
}
// if(shouldPop) {
// dispatch_async(dispatch_get_main_queue(), ^{
// [self popViewControllerAnimated:YES];
// });
// }
// else {
// // Workaround for iOS7.1. Thanks to @boliva - http://stackoverflow.com/posts/comments/34452906
// for(UIView *subview in [navigationBar subviews]) {
// if(subview.alpha < 1.) {
// [UIView animateWithDuration:.25 animations:^{
// subview.alpha = 1.;
// }];
// }
// }
// }
return NO;
}
@end
#define HIDE_BOTTOMBAR_HIERARCHY (2) // >= 2 从第几层开始hideTabBar
@implementation UIViewController (LogicController)
- (UIImage *)getViewControllerImage:(CGSize)imageSize {
CGFloat scale = [[UIScreen mainScreen] scale];
UIImage *snapshot = nil;
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, scale);
{
if ([self.view respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {
[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];
}
else {
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
}
snapshot = UIGraphicsGetImageFromCurrentImageContext();
}
UIGraphicsEndImageContext();
return snapshot;
}
#pragma mark - Navigation
- (BOOL)isCurrentViewController {
UIViewController * vc = [self.navigationController topViewController];
return vc == self;
}
- (void)onBackButtonClicked {
dispatch_async(dispatch_get_main_queue(), ^{
[self PopViewControllerAnimated:YES];
});
}
- (UIViewController *)getViewControllerAtIndex:(NSInteger)iIndex {
NSInteger legalIndex = iIndex;
NSInteger maxCount = [self.navigationController.viewControllers count];
if (legalIndex < 0) {
legalIndex = MAX((maxCount - 1 + legalIndex), 0);
}
if (legalIndex >= maxCount) {
return nil;
}
return self.navigationController.viewControllers[ legalIndex ];
}
- (void)PushViewController:(UIViewController *)viewController animated:(BOOL)bAnimated {
BOOL isFirstHideTabbarCtrl = NO;
UINavigationController *rootNavCtrl = self.navigationController;
while (rootNavCtrl.navigationController) {
rootNavCtrl = rootNavCtrl.navigationController;
}
if (rootNavCtrl.tabBarController) {
if ([self.navigationController.viewControllers count] == (HIDE_BOTTOMBAR_HIERARCHY - 1)) {
isFirstHideTabbarCtrl = YES;
}
viewController.hidesBottomBarWhenPushed = YES;
self.hidesBottomBarWhenPushed = YES;
}
[self.navigationController pushViewController:viewController animated:bAnimated];
if (isFirstHideTabbarCtrl) {
self.hidesBottomBarWhenPushed = NO;
}
}
- (UIViewController *)PopViewControllerAnimated:(BOOL)bAnimated {
return [self.navigationController popViewControllerAnimated:bAnimated];
}
- (NSArray *)PopToViewController:(UIViewController *)viewController animated:(BOOL)bAnimated {
return [self.navigationController popToViewController:viewController animated:bAnimated];
}
- (NSArray *)PopToRootViewControllerAnimated:(BOOL)bAnimated {
return [self.navigationController popToRootViewControllerAnimated:bAnimated];
}
- (NSArray *)PopToViewControllerWithClass:(Class)vcClass animated:(BOOL)bAnimated {
NSEnumerator *currentVCs = [self.navigationController.viewControllers reverseObjectEnumerator];
UIViewController *foundVC = nil;
for (UIViewController *vc in currentVCs) {
if ([vc isKindOfClass:vcClass]) {
foundVC = vc;
break;
}
}
if (foundVC) {
return [self.navigationController popToViewController:foundVC animated:bAnimated];
}
else {
return nil;
}
}
- (NSArray *)PopToViewControllerAtIndex:(NSInteger)index animated:(BOOL)bAnimated {
UIViewController *vc = [self getViewControllerAtIndex:index];
if (!vc) {
return nil;
}
return [self.navigationController popToViewController:vc animated:bAnimated];
}
@end
#import "IBTUINavigationController.h"
@implementation UIViewController (ModalView)
//- (void)releasePopoverController:(id)controller;
//- (void)popoverControllerDidDismissPopover:(id)popoverController;
- (void)DismissMyselfAnimated:(BOOL)bAnimated {
[self.presentingViewController dismissViewControllerAnimated:bAnimated completion:NULL];
}
- (void)DismissModalViewControllerAnimated:(BOOL)bAnimated {
[self dismissViewControllerAnimated:bAnimated completion:NULL];
}
- (void)PresentModalViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)bAnimated {
[self presentViewController:viewControllerToPresent animated:bAnimated completion:NULL];
}
- (void)PresentViewControllerInNewNavigation:(UIViewController *)viewControllerToPresent animated:(BOOL)bAnimated completion:(void (^)(void))completion {
IBTUINavigationController *navCtrl = [[IBTUINavigationController alloc] initWithRootViewController:viewControllerToPresent];
[self presentViewController:navCtrl animated:bAnimated completion:completion];
}
@end
@implementation UIViewController (margin)
- (void)setLeftBarButtonItem:(UIBarButtonItem *)item {
self.navigationItem.leftBarButtonItem = item;
}
- (UIBarButtonItem *)leftBarButtonItem {
return self.navigationItem.leftBarButtonItem;
}
- (void)setRightBarButtonItem:(UIBarButtonItem *)item {
self.navigationItem.rightBarButtonItem = item;
}
- (UIBarButtonItem *)rightBarButtonItem {
return self.navigationItem.rightBarButtonItem;
}
- (void)setLeftBarButtonItems:(NSArray *)items {
self.navigationItem.leftBarButtonItems = items;
}
- (void)setRightBarButtonItems:(NSArray *)items {
self.navigationItem.rightBarButtonItems = items;
}
- (UIBarButtonItem *)addLeftBarBtnItemWithName:(NSString *)btnName action:(SEL)selector {
UIBarButtonItem *barBtnItem =
[[UIBarButtonItem alloc] initWithTitle:btnName style:UIBarButtonItemStylePlain target:self action:selector];
if (self.navigationItem.leftBarButtonItems) {
NSMutableArray *marrBtnItems = [self.navigationItem.leftBarButtonItems mutableCopy];
[marrBtnItems addObject:barBtnItem];
self.navigationItem.leftBarButtonItems = marrBtnItems;
}
else {
self.navigationItem.leftBarButtonItems = @[ barBtnItem ];
}
return barBtnItem;
}
- (UIBarButtonItem *)addRightBarBtnItemWithName:(NSString *)btnName action:(SEL)selector {
UIBarButtonItem *barBtnItem =
[[UIBarButtonItem alloc] initWithTitle:btnName style:UIBarButtonItemStylePlain target:self action:selector];
if (self.navigationItem.rightBarButtonItems) {
NSMutableArray *marrBtnItems = [self.navigationItem.rightBarButtonItems mutableCopy];
[marrBtnItems addObject:barBtnItem];
self.navigationItem.rightBarButtonItems = marrBtnItems;
}
else {
self.navigationItem.rightBarButtonItems = @[ barBtnItem ];
}
return barBtnItem;
}
@end
//
// IBTAdditionsObserver.h
// Cruiser
//
// Created by Xummer on 3/26/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "IBTObject.h"
@interface IBTAdditionsObserver : IBTObject
+ (IBTAdditionsObserver *)sharedInstance;
@end
//
// IBTAdditionsObserver.m
// Cruiser
//
// Created by Xummer on 3/26/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "IBTAdditionsObserver.h"
#import "UIApplication+CheckFirstRun.h"
static IBTAdditionsObserver *sSharedInstance;
@implementation IBTAdditionsObserver
+ (void)load {
[self performSelectorOnMainThread:@selector(sharedInstance)
withObject:nil waitUntilDone:NO];
}
+ (IBTAdditionsObserver *)sharedInstance {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sSharedInstance = [[IBTAdditionsObserver alloc] init];
});
return sSharedInstance;
}
- (id)init {
self = [super init];
if (self) {
NSNotificationCenter *notiCenter = [NSNotificationCenter defaultCenter];
[notiCenter addObserver:self
selector:@selector(AppWillTerminate)
name:UIApplicationWillResignActiveNotification
object:nil];
}
return self;
}
- (void)AppWillTerminate {
[[UIApplication sharedApplication] setNotFirstRun];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
//
// ICRBaseViewController.h
// Cruiser
//
// Created by Xummer on 3/22/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "IBTUIViewController.h"
@interface ICRBaseViewController : IBTUIViewController
@end
//
// ICRBaseViewController.m
// Cruiser
//
// Created by Xummer on 3/22/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "ICRBaseViewController.h"
@interface ICRBaseViewController ()
@end
@implementation ICRBaseViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
// self.view.backgroundColor = [UIColor whiteColor];
}
ON_DID_APPEAR( signal )
{
self.view.backgroundColor = [UIColor whiteColor];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
//
// ICRDatePickerViewController.h
// Cruiser
//
// Created by Xummer on 4/20/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "ICRBaseViewController.h"
@class IBTDatePickerViewController;
@protocol IBTDatePickerDelegate <NSObject>
- (void)datePickerVCtrl:(IBTDatePickerViewController *)pickerVCtrl didSelectedDate:(NSDate *)selectDate;
@end
@interface IBTDatePickerViewController : ICRBaseViewController
@property (weak, nonatomic) id <IBTDatePickerDelegate> delegate;
- (void)setSelectedDate:(NSDate *)selectedDate;
@end
//
// ICRDatePickerViewController.m
// Cruiser
//
// Created by Xummer on 4/20/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "IBTDatePickerViewController.h"
#import "IBTCommon.h"
#import "NSDate+FormatterAdditions.h"
#import "UIViewController+LogicController.h"
@interface IBTDatePickerViewController ()
@property (strong, nonatomic) UIDatePicker *datePicker;
@property (strong, nonatomic) NSDate *m_oSelectedDate;
@end
@implementation IBTDatePickerViewController
#pragma mark - Life Cycle
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self setupSubviews];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
CGRect frame = _datePicker.frame;
frame.origin.y = (CGRectGetHeight(self.view.bounds) - CGRectGetHeight(frame)) * (1 - 0.618);
_datePicker.frame = frame;
}
#pragma mark - Public Method
- (void)setSelectedDate:(NSDate *)selectedDate {
self.m_oSelectedDate = selectedDate;
}
#pragma mark - Private Method
- (void)setupSubviews {
[self addRightBarBtnItemWithName:[IBTCommon localizableString:@"Done"]
action:@selector(onDoneButtonAction:)];
self.datePicker = [[UIDatePicker alloc] init];
_datePicker.datePickerMode = UIDatePickerModeDate;
_datePicker.minimumDate = [NSDate date];
if (self.m_oSelectedDate) {
_datePicker.date = self.m_oSelectedDate;
}
[self.view addSubview:_datePicker];
}
#pragma mark - Actions
- (void)onDoneButtonAction:(__unused id)sender {
if ([_delegate respondsToSelector:@selector(datePickerVCtrl:didSelectedDate:)]) {
[_delegate datePickerVCtrl:self didSelectedDate:[_datePicker.date endOfTheDay]];
}
}
@end
//
// IBTFileManager.h
// Cruiser
//
// Created by Xummer on 15/6/15.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "IBTObject.h"
@interface IBTFileManager : IBTObject
+ (NSNumber *)sizeForFileAtPath:(NSString *)filePath;
+ (BOOL)removeFileAtUrl:(NSURL *)filePathUrl;
+ (BOOL)removeFileAtPath:(NSString *)filePath;
+ (BOOL)moveFile:(NSURL *)fromPath toPath:(NSURL *)toPath;
@end
//
// IBTFileManager.m
// Cruiser
//
// Created by Xummer on 15/6/15.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "IBTFileManager.h"
@implementation IBTFileManager
// File Size
+ (NSNumber *)sizeForFileAtPath:(NSString *)filePath {
NSError *attributesError;
NSDictionary *fileAttributes =
[[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:&attributesError];
if (!attributesError) {
return fileAttributes[ NSFileSize ] ? : @(0);
}
else {
return @(0);
}
}
+ (BOOL)removeFileAtPath:(NSString *)filePath {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
if ([fileManager fileExistsAtPath:filePath]) {
[fileManager removeItemAtPath:filePath error:&error];
}
else {
return YES;
}
if (error) {
NSLog(@"%@",error);
return NO;
}
else{
return YES;
}
}
+ (BOOL)removeFileAtUrl:(NSURL *)filePathUrl {
if (!filePathUrl ) {
return NO;
}
NSString *filePathStr = [filePathUrl path];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
if ([fileManager fileExistsAtPath:filePathStr]) {
[fileManager removeItemAtURL:filePathUrl error:&error];
}
else {
return YES;
}
if (error) {
NSLog(@"%@",error);
return NO;
}
else{
return YES;
}
}
+ (BOOL)moveFile:(NSURL *)fromPath toPath:(NSURL *)toPath
{
if (!toPath || !fromPath) {
return NO;
}
NSString *fromPathStr = [fromPath path];
NSString *toPathStr = [toPath path];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = nil;
if ([fileManager fileExistsAtPath:fromPathStr]) {
[fileManager moveItemAtPath:fromPathStr toPath:toPathStr error:&error];
}
if (error) {
NSLog(@"%@",error);
return NO;
}
else{
return YES;
}
}
@end
//
// ICRUIAppearance.h
// Cruiser
//
// Created by Xummer on 3/31/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "IBTObject.h"
@interface ICRUIAppearance : IBTObject
+ (void)CustomAppearance;
+ (void)customNavigationbarAppearance;
@end
//
// ICRUIAppearance.m
// Cruiser
//
// Created by Xummer on 3/31/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "ICRUIAppearance.h"
#import "IBTConstants.h"
@interface UILabel (Appearance)
@property (assign, nonatomic) UIColor *labelBackgroundColor UI_APPEARANCE_SELECTOR;
@end
@implementation UILabel (Appearance)
@dynamic labelBackgroundColor;
- (void)setLabelBackgroundColor:(UIColor *)labelBackgroundColor {
[super setBackgroundColor:labelBackgroundColor];
}
@end
@implementation ICRUIAppearance
+ (void)CustomAppearance {
if (IBT_IOS7_OR_LATER) {
UIApplication.sharedApplication.delegate.window.tintColor = [UIColor colorWithR:63 g:134 b:244 a:1];
}
[[self class] customNavigationbarAppearance];
[[self class] customTabbarAppearance];
[[self class] customLableAppearance];
}
+ (void)customNavigationbarAppearance {
[UINavigationBar appearance].barTintColor = [UIColor colorWithR:63 g:134 b:244 a:1];
[UINavigationBar appearance].tintColor = [UIColor whiteColor];
//Universal
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowOffset = CGSizeZero;
[[UINavigationBar appearance] setTitleTextAttributes:
@{ NSForegroundColorAttributeName: [UIColor whiteColor],
NSFontAttributeName: [UIFont boldSystemFontOfSize:20],
NSShadowAttributeName: shadow}];
}
+ (void)customTabbarAppearance {
if (IBT_IOS7_OR_LATER) {
[[UITabBar appearance] setBarTintColor:[UIColor colorWithR:36 g:38 b:53 a:1]];
}
else {
[[UITabBar appearance] setTintColor:[UIColor colorWithR:36 g:38 b:53 a:1]];
}
UIImage *selTab = [[UIImage imageNamed:@"TabbarSelectedBG"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
CGSize tabSize = CGSizeMake(IBT_MAIN_SCREEN_WIDTH/4, 49);
UIGraphicsBeginImageContext(tabSize);
[selTab drawInRect:CGRectMake(0, 0, tabSize.width, tabSize.height)];
UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[UITabBar appearance] setSelectionIndicatorImage:reSizeImage];
}
+ (void)customLableAppearance {
if (IBT_IOS7_OR_LATER) {
}
else {
[[UILabel appearance] setLabelBackgroundColor:[UIColor clearColor]];
}
}
@end
//
// ICRAttachTitleView.h
// Cruiser
//
// Created by Xummer on 15/4/15.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "IBTUIView.h"
#import "IBTUIKit.h"
#define ICRATTACH_TITLE_VIEW_HEIGHT (50.0f)
#define ICRATTACH_TITLE_VIEW_WIDTH (50.0f)
@interface ICRAttachTitleView : IBTUIView
@end
@interface ICRAttachTitleView (Configure)
- (void)updateWithTitle:(NSString *)title iconName:(NSString *)iconName;
@end
//
// ICRAttachTitleView.m
// Cruiser
//
// Created by Xummer on 15/4/15.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "ICRAttachTitleView.h"
#define AT_VERTICAL_MARGIN (10.0f)
#define AT_HORIZON_MARGIN (10.0f)
@interface ICRAttachTitleView ()
@property (strong, nonatomic) UIImageView *m_icon;
@property (strong, nonatomic) IBTUILabel *m_titleLabel;
@end
@implementation ICRAttachTitleView
#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (!self) {
return nil;
}
[self initSubviews];
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGFloat fDy = AT_HORIZON_MARGIN;
CGFloat fW = self.width - 2 * fDy;
_m_icon.frame = (CGRect){
.origin.x = fDy,
.origin.y = 0,
.size.width = fW,
.size.height = fW
};
_m_titleLabel.frame = (CGRect){
.origin.x = 0,
.origin.y = _m_icon.bottom,
.size.width = self.width,
.size.height = 16
};
}
#pragma mark - Private Method
- (void)initSubviews {
self.backgroundColor = [UIColor clearColor];
self.m_icon = [[UIImageView alloc] init];
[self addSubview:_m_icon];
self.m_titleLabel = [[IBTUILabel alloc] init];
_m_titleLabel.textAlignment = NSTextAlignmentCenter;
_m_titleLabel.textColor = [UIColor lightGrayColor];
_m_titleLabel.font = [UIFont systemFontOfSize:12.0f];
[self addSubview:_m_titleLabel];
}
@end
@implementation ICRAttachTitleView (Configure)
- (void)updateWithTitle:(NSString *)title iconName:(NSString *)iconName {
self.m_titleLabel.text = title;
self.m_icon.image = [UIImage imageNamed:iconName];
}
@end
//
// ICRAttachmentUnit.h
// Cruiser
//
// Created by Xummer on 4/19/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "IBTUIControl.h"
typedef NS_ENUM(NSUInteger, AttachmentContentType) {
kICRTypeUnknow = 0,
kICRTypeImage,
kICRTypeVideo,
kICRTypeAudio,
kICRTypeCustom,
};
typedef NS_ENUM(NSUInteger, AttachmentUnitType) {
kATTNormal = 0,
kATTCloseBtn,
};
typedef NS_ENUM(NSUInteger, AttachmentDisplayType) {
kATTDisplayOutTitle = 0,
kATTDisplayInnerTitle,
};
#define IBT_ATTACH_UNIT_DEFAULT_WIDTH (40)
#define IBT_ATTACH_UNIT_TITLE_HEIGHT (30)
#define IBT_ATTACH_UNIT_DEFAULT_HEIGHT (IBT_ATTACH_UNIT_DEFAULT_WIDTH + IBT_ATTACH_UNIT_TITLE_HEIGHT)
@interface ICRAttachmentUnit : IBTUIControl
@property (assign, nonatomic) NSUInteger m_uiAttachIndex;
@property (strong, nonatomic) UIButton *m_closeButton;
@property (assign, nonatomic) AttachmentDisplayType m_eCurDisplayType;
@property (assign, nonatomic) AttachmentContentType m_eCurFileType;
@property (strong, nonatomic) id m_oAttachmentWrap;
- (void)updateWithType:(AttachmentUnitType)type
masker:(UIImage *)masker
placeHolder:(UIImage *)phImage
image:(id)image
title:(NSString *)title;
@end
//
// ICRAttachmentUnit.m
// Cruiser
//
// Created by Xummer on 4/19/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "ICRAttachmentUnit.h"
#import "UIColor+Helper.h"
#import "UIImageView+WebCache.h"
#define IBT_ATTACH_IMAGE_CORNER_RADIUS (4)
#define IBT_ATTACH_TOP_PADDING (10)
#define IBT_ATTACH_AUDIO_HEIGHT (30)
@interface ICRAttachmentUnit ()
{
AttachmentUnitType m_eCurAttachType;
}
@property (strong, nonatomic) UIImageView *m_imageView;
@property (strong, nonatomic) UILabel *m_titleLabel;
@property (strong, nonatomic) UIImageView *m_iconMask;
@end
@implementation ICRAttachmentUnit
#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (!self) {
return nil;
}
[self initSubviews];
return self;
}
- (void)didMoveToSuperview {
[super didMoveToSuperview];
if (self.superview) {
[self bringSubviewToFront:_m_titleLabel];
[self.superview addSubview:_m_closeButton];
}
}
- (void)removeFromSuperview {
[_m_closeButton removeFromSuperview];
[super removeFromSuperview];
}
- (void)layoutSubviews {
[super layoutSubviews];
_m_titleLabel.hidden = [_m_titleLabel.text length] == 0;
if (_m_eCurFileType == kICRTypeAudio) {
_m_imageView.frame = (CGRect){
.origin.x = 0,
.origin.y = IBT_ATTACH_TOP_PADDING,
.size.width = IBT_ATTACH_UNIT_DEFAULT_WIDTH + 20,
.size.height = IBT_ATTACH_AUDIO_HEIGHT
};
_m_titleLabel.frame = (CGRect){
.origin.x = 0,
.origin.y = 0,
.size.width = IBT_ATTACH_UNIT_DEFAULT_WIDTH - 10,
.size.height = IBT_ATTACH_AUDIO_HEIGHT
};
CGFloat h = 16;
_m_iconMask.frame = (CGRect){
.origin.x = CGRectGetMaxX(_m_titleLabel.frame),
.origin.y = (CGRectGetHeight(_m_imageView.bounds) - h) * .5f,
.size.width = h,
.size.height = h
};
_m_iconMask.layer.cornerRadius = 0;
}
else {
_m_imageView.frame = (CGRect){
.origin.x = 0,
.origin.y = IBT_ATTACH_TOP_PADDING,
.size.width = IBT_ATTACH_UNIT_DEFAULT_WIDTH,
.size.height = IBT_ATTACH_UNIT_DEFAULT_WIDTH
};
_m_iconMask.frame = _m_imageView.bounds;
CGFloat h = IBT_ATTACH_UNIT_TITLE_HEIGHT - 10;
CGFloat dy = 10;
switch (_m_eCurDisplayType) {
case kATTDisplayOutTitle:
{
dy = CGRectGetMaxY(_m_imageView.frame);
}
break;
case kATTDisplayInnerTitle:
{
dy = CGRectGetHeight(_m_imageView.bounds) - h;
}
break;
default:
break;
}
_m_titleLabel.frame = (CGRect){
.origin.x = 0,
.origin.y = dy,
.size.width = CGRectGetWidth(_m_imageView.bounds),
.size.height = h
};
_m_iconMask.layer.cornerRadius = _m_imageView.layer.cornerRadius;
}
CGFloat w = 22;
CGFloat delta = - (1 - 0.618f) * w;
_m_closeButton.frame = (CGRect){
.origin.x = CGRectGetMaxX(self.frame) - 0.618f * w,
.origin.y = CGRectGetMinY(self.frame) + CGRectGetMinY(_m_imageView.frame) + delta ,
.size.width = w,
.size.height = w
};
}
#pragma mark - Setter
- (void)setM_eCurDisplayType:(AttachmentDisplayType)eCurDisplayType {
if (_m_eCurDisplayType == eCurDisplayType) {
return;
}
_m_eCurDisplayType = eCurDisplayType;
switch (_m_eCurDisplayType) {
case kATTDisplayOutTitle:
{
self.m_titleLabel.backgroundColor = [UIColor clearColor];
self.m_titleLabel.textColor = [UIColor grayColor];
[self addSubview:_m_titleLabel];
}
break;
case kATTDisplayInnerTitle:
{
if (_m_eCurFileType == kICRTypeAudio) {
self.m_titleLabel.backgroundColor = [UIColor clearColor];
}
else {
self.m_titleLabel.backgroundColor = [UIColor colorWithW:1 a:.8];
}
self.m_titleLabel.textColor = [UIColor whiteColor];
[self.m_imageView addSubview:_m_titleLabel];
}
break;
default:
break;
}
[self setNeedsLayout];
}
#pragma mark - Public Method
- (void)updateWithType:(AttachmentUnitType)type
masker:(UIImage *)masker
placeHolder:(UIImage *)phImage
image:(id)image
title:(NSString *)title
{
BOOL haveCloseBtn = NO;
switch (type) {
case kATTNormal:
{
haveCloseBtn = NO;
}
break;
case kATTCloseBtn:
{
haveCloseBtn = YES;
}
break;
default:
break;
}
_m_closeButton.hidden = !haveCloseBtn;
self.clipsToBounds = _m_closeButton.hidden;
self.highLightWhenTapped = _m_iconMask.hidden;
self.m_iconMask.image = masker;
if ([image isKindOfClass:[UIImage class]]) {
_m_imageView.image = image;
}
else if ([image isKindOfClass:[NSURL class]]) {
[_m_imageView sd_setImageWithURL:image placeholderImage:phImage];
}
else {
_m_imageView.image = phImage;
}
_m_titleLabel.text = title;
switch (_m_eCurDisplayType) {
case kATTDisplayInnerTitle:
{
if (_m_eCurFileType == kICRTypeAudio) {
self.m_titleLabel.backgroundColor = [UIColor clearColor];
}
else {
self.m_titleLabel.backgroundColor = [UIColor colorWithW:1 a:.8];
}
}
break;
default:
break;
}
}
#pragma mark - Private Method
- (void)initSubviews {
self.backgroundColor = [UIColor clearColor];
self.highLightWhenTapped = YES;
self.m_imageView = [[UIImageView alloc] init];
_m_imageView.layer.cornerRadius = IBT_ATTACH_IMAGE_CORNER_RADIUS;
_m_imageView.layer.masksToBounds = YES;
[self addSubview:_m_imageView];
self.m_iconMask = [[UIImageView alloc] init];
_m_iconMask.layer.masksToBounds = YES;
_m_iconMask.contentMode = UIViewContentModeCenter;
[_m_imageView addSubview:_m_iconMask];
self.m_titleLabel = [[UILabel alloc] init];
_m_titleLabel.textColor = [UIColor grayColor];
_m_titleLabel.textAlignment = NSTextAlignmentCenter;
_m_titleLabel.font = [UIFont systemFontOfSize:12];
[self addSubview:_m_titleLabel];
self.m_closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_m_closeButton setImage:[UIImage imageNamed:@"attachment_delete_btn"]
forState:UIControlStateNormal];
self.m_closeButton.hidden = YES;
}
@end
//
// ICRAttachmentView.h
// Cruiser
//
// Created by Xummer on 15/4/15.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "IBTUIView.h"
#import "ICRAttachmentUnit.h"
#import "IBTUIKit.h"
typedef NS_ENUM(NSUInteger, ICRAttViewType) {
kAttViewImage = 0,
kAttViewTask,
kAttViewVoice,
};
@interface ICRAttachmentView : IBTUIView
@property (strong, nonatomic) UIButton *m_addButton;
@property (strong, nonatomic) IBTUIScrollView *m_scrollView;
@property (strong, nonatomic) NSMutableArray *m_arrAttViews;
@property (assign, nonatomic) NSUInteger m_uiMaxAttCount;
- (instancetype)initWithType:(ICRAttViewType)eType;
- (void)addContentAttachmentView:(ICRAttachmentUnit *)attView;
- (void)removeContentAttachmentViewAtIndex:(NSUInteger)uiIndex;
@end
//
// ICRAttachmentView.m
// Cruiser
//
// Created by Xummer on 15/4/15.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "ICRAttachmentView.h"
#import "ICRAttachTitleView.h"
#define ADD_BTN_WIDTH (44.0f)
#define ATTVIEW_INNER_GAP (5.0f)
@interface ICRAttachmentView ()
{
ICRAttViewType m_eViewType;
}
@property (strong, nonatomic) ICRAttachTitleView *m_titleView;
@end
@implementation ICRAttachmentView
#pragma mark - Life Cycle
- (instancetype)initWithType:(ICRAttViewType)eType {
self = [super initWithFrame:CGRectZero];
if (!self) {
return nil;
}
m_eViewType = eType;
self.m_arrAttViews = [NSMutableArray array];
[self initSubviews];
return self;
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (!self) {
return nil;
}
self.m_arrAttViews = [NSMutableArray array];
[self initSubviews];
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGFloat fDelta = 10;
_m_titleView.frame = (CGRect){
.origin.x = 0,
.origin.y = (self.height - ICRATTACH_TITLE_VIEW_HEIGHT) * .5f + fDelta,
.size.width = ICRATTACH_TITLE_VIEW_WIDTH,
.size.height = ICRATTACH_TITLE_VIEW_HEIGHT
};
_m_addButton.frame = (CGRect){
.origin.x = self.width - ADD_BTN_WIDTH,
.origin.y = (self.height - ADD_BTN_WIDTH) * .5f + fDelta,
.size.width = ADD_BTN_WIDTH,
.size.height = ADD_BTN_WIDTH
};
CGFloat fDx = _m_titleView.right + ATTVIEW_INNER_GAP;
_m_scrollView.frame = (CGRect){
.origin.x = fDx,
.origin.y = 0,
.size.width = _m_addButton.left - fDx - ATTVIEW_INNER_GAP,
.size.height = self.height
};
}
#pragma mark - Public Method
- (void)addContentAttachmentView:(ICRAttachmentUnit *)attView {
UIView *lastView = [_m_arrAttViews lastObject];
CGFloat fX = (lastView ? lastView.right : 0) + ATTVIEW_INNER_GAP;
attView.origin = (CGPoint){
.x = fX,
.y = (_m_scrollView.height - attView.height) * .5f
};
attView.m_uiAttachIndex = [_m_arrAttViews count];
attView.m_closeButton.tag = attView.m_uiAttachIndex;
[attView.m_closeButton addTarget:self action:@selector(onCloseButtonAction:)
forControlEvents:UIControlEventTouchUpInside];
[self.m_scrollView addSubview:attView];
[self.m_arrAttViews addObject:attView];
_m_scrollView.contentSize = CGSizeMake(attView.right + ATTVIEW_INNER_GAP, _m_scrollView.height);
[self checkIsReachedMaxCount];
}
- (void)removeContentAttachmentViewAtIndex:(NSUInteger)uiIndex {
if (uiIndex < [_m_arrAttViews count]) {
ICRAttachmentUnit *unit = _m_arrAttViews[ uiIndex ];
[self removeContentAttachmentView:unit];
}
}
- (void)removeContentAttachmentView:(ICRAttachmentUnit *)attView {
[attView removeFromSuperview];
[_m_arrAttViews removeObject:attView];
[self checkIsReachedMaxCount];
[self relayoutContentView];
}
- (void)checkIsReachedMaxCount {
if (_m_uiMaxAttCount > 0) {
self.m_addButton.hidden = [_m_arrAttViews count] >= _m_uiMaxAttCount;
}
}
- (void)relayoutContentView {
NSUInteger uiIndex = 0;
CGFloat fX = ATTVIEW_INNER_GAP;
for (ICRAttachmentUnit *attV in _m_arrAttViews) {
attV.m_uiAttachIndex = uiIndex;
attV.m_closeButton.tag = uiIndex;
attV.origin = (CGPoint){
.x = fX,
.y = (_m_scrollView.height - attV.height) * .5f
};
fX = attV.right + ATTVIEW_INNER_GAP;
}
_m_scrollView.contentSize = CGSizeMake(fX, _m_scrollView.height);
}
#pragma mark - Private Method
- (void)initSubviews {
self.m_titleView = [[ICRAttachTitleView alloc] init];
[self addSubview:_m_titleView];
self.m_scrollView = [[IBTUIScrollView alloc] init];
[self addSubview:_m_scrollView];
self.m_addButton = [IBTUIButton buttonWithType:UIButtonTypeCustom];
[self addSubview:_m_addButton];
self.m_arrAttViews = [NSMutableArray array];
NSString *nsTitle = nil;
NSString *nsIconName = nil;
NSString *nsAddBtnName = nil;
switch (m_eViewType) {
case kAttViewImage:
{
nsTitle = [IBTCommon localizableString:@"Add Photo"];
nsIconName = @"AttachCamera";
nsAddBtnName = @"AttachmentAddBtn";
}
break;
case kAttViewTask:
{
nsTitle = [IBTCommon localizableString:@"Related Task"];
nsIconName = @"AttachCamera";
nsAddBtnName = @"AttachmentAddBtn";
}
break;
case kAttViewVoice:
{
nsTitle = [IBTCommon localizableString:@"Record"];
nsIconName = @"RecordIcon";
nsAddBtnName = @"AttachmentAddBtn";
}
break;
default:
break;
}
[_m_addButton setImage:[UIImage imageNamed:nsAddBtnName]
forState:UIControlStateNormal];
[_m_titleView updateWithTitle:nsTitle iconName:nsIconName];
}
#pragma mark - Action
- (void)onCloseButtonAction:(id)sender {
UIButton *closeBtn = sender;
[self removeContentAttachmentViewAtIndex:closeBtn.tag];
}
@end
//
// IBTTextFieldCell.h
// Cruiser
//
// Created by Lili Wang on 15/4/3.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
static const CGFloat JTLeftMinLabelWidth = 119;
#import "IBTTableViewCell.h"
#import "IBTUITextField.h"
@interface IBTTextFieldCell : IBTTableViewCell
@property (strong, nonatomic) IBTUITextField *textField;
@property (assign, nonatomic) BOOL textIsIllegal;
- (void)updateTextIsIllegal:(BOOL)textIsIllegal;
@end
//
// IBTTextFieldCell.m
// Cruiser
//
// Created by Lili Wang on 15/4/3.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "IBTTextFieldCell.h"
#import "IBTConstants.h"
@implementation IBTTextFieldCell
#pragma mark - Life Cycle
- (id)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self _init];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect textFieldFrame = CGRectZero;
if ([self.textLabel.text length] > 0) {
self.textLabel.frame = ({
CGRect frame = self.textLabel.frame;
frame.size.width = MIN(MAX([self.textLabel sizeThatFits:CGSizeZero].width, JTLeftMinLabelWidth), JTLeftMinLabelWidth);
frame;
});
CGFloat textFieldX = CGRectGetMaxX(self.textLabel.frame) + 5;
textFieldFrame = (CGRect){
.origin.x = textFieldX,
.origin.y = 0,
.size.width = CGRectGetWidth(_textField.superview.bounds) - IBT_GROUP_CELL_LEFT_PADDING - textFieldX,
.size.height = CGRectGetHeight(_textField.superview.bounds)
};
}
else {
textFieldFrame = (CGRect){
.origin.x = IBT_GROUP_CELL_LEFT_PADDING,
.origin.y = 0,
.size.width = CGRectGetWidth(_textField.superview.bounds) - IBT_GROUP_CELL_LEFT_PADDING * 2,
.size.height = CGRectGetHeight(_textField.superview.bounds)
};
}
_textField.frame = textFieldFrame;
}
- (void)updateTextIsIllegal:(BOOL)textIsIllegal {
_textIsIllegal = textIsIllegal;
}
#pragma mark - Setter
- (void)setTextIsIllegal:(BOOL)textIsIllegal {
_textIsIllegal = textIsIllegal;
if (self.textLabel) {
self.textLabel.textColor = _textIsIllegal ? [UIColor redColor] : [UIColor blackColor];
self.textField.textColor = self.textLabel.textColor;
}
else {
self.textField.textColor = _textIsIllegal ? [UIColor redColor] : [UIColor blackColor];
}
}
#pragma mark - Private Method
- (void)_init {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.textField = [[IBTUITextField alloc] init];
[self.contentView addSubview:_textField];
[self.contentView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self.textField action:NSSelectorFromString(@"becomeFirstResponder")]];
}
@end
//
// ICRFunctionBaseView.h
// Cruiser
//
// Created by Lili Wang on 15/4/1.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "ICRFunctionItemControl.h"
@protocol ICRFunctionBaseViewDelegate;
@interface ICRFunctionBaseView : UIView//<ICRFuctionItemControlDelegate>
@property (weak, nonatomic) id <ICRFunctionBaseViewDelegate> m_delegate;
+ (ICRFunctionBaseView *)initWithFunctionData:(NSArray *)arrFunctions;
@end
@protocol ICRFunctionBaseViewDelegate <NSObject>
@optional
- (void)ICRFunctionBaseView:(ICRFunctionItemControl *)imageView;
@end
\ No newline at end of file
//
// ICRFunctionBaseView.m
// Cruiser
//
// Created by Lili Wang on 15/4/1.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#define FUNCTION_COUNT_EACH_ROW (3)
#define MODULE_VIEW_WIDTH IBT_MAIN_SCREEN_WIDTH/FUNCTION_COUNT_EACH_ROW
#define HEIGHT_WIDTH_PROPORTION 112.0/105.0
#define MODULE_VIEW_HEIGHT MODULE_VIEW_WIDTH * HEIGHT_WIDTH_PROPORTION
#import "ICRFunctionBaseView.h"
#import "ICRFunctionEntity.h"
#import "IBTUIKit.h"
@interface ICRFunctionBaseView()
@property (nonatomic, assign) NSUInteger m_rows;
@property (nonatomic, assign) NSUInteger m_imageCountsOfLastRow;
@property (nonatomic, strong) NSArray *m_arrFunctions;
@end
@implementation ICRFunctionBaseView
#pragma mark - life Cycle
- (id) initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// code
}
return self;
}
#pragma mark - Public Method
+ (ICRFunctionBaseView *)initWithFunctionData:(NSArray *)arrFunctions {
ICRFunctionBaseView *baseView = [[ICRFunctionBaseView alloc] init];
baseView.m_rows = [baseView calculateShowRows:arrFunctions];
baseView.m_imageCountsOfLastRow = [baseView calculateRemainderLastRow:arrFunctions];
NSUInteger count = FUNCTION_COUNT_EACH_ROW;
for (int i = 0; i < baseView.m_rows; i ++) {
if (i == baseView.m_rows - 1 && baseView.m_imageCountsOfLastRow > 0) {
count = baseView.m_imageCountsOfLastRow;
}
for (int j = 0; j < count; j ++) {
int indexValue = FUNCTION_COUNT_EACH_ROW * i + j;
ICRFunctionEntity *functionEntity = [arrFunctions objectAtIndex:indexValue];
UIImage *functionImage = [UIImage imageNamed:functionEntity.iconName];
NSString *functionLabelTitle = functionEntity.functionName;
ICRFunctionItemControl *fControl = [ICRFunctionItemControl highLightControl];
fControl.frame = (CGRect){
.origin.x = MODULE_VIEW_WIDTH * j,
.origin.y = MODULE_VIEW_HEIGHT * i,
.size.width = MODULE_VIEW_WIDTH,
.size.height = MODULE_VIEW_HEIGHT
};
fControl.functinNameLabel.text = functionLabelTitle;
fControl.functionImage.image = functionImage;
fControl.tag = functionEntity.functionItemTag;
[fControl addTarget:baseView action:@selector(singleImageClike:) forControlEvents:UIControlEventTouchUpInside];
[baseView addSubview:fControl];
}
}
return baseView;
}
#pragma mark - Private Method
- (NSUInteger)calculateShowRows:(NSArray *)arrImages {
NSUInteger remainder = arrImages.count % FUNCTION_COUNT_EACH_ROW;
NSUInteger rows = arrImages.count / FUNCTION_COUNT_EACH_ROW;
rows = remainder > 0 ? rows + 1 : rows;
return rows;
}
- (NSUInteger)calculateRemainderLastRow:(NSArray *)arrImages {
return arrImages.count % FUNCTION_COUNT_EACH_ROW;
}
#pragma mark - ICRFuctionItemControlDelegate
- (void)singleImageClike:(ICRFunctionItemControl *)imageView {
if ([self.m_delegate respondsToSelector:@selector(ICRFunctionBaseView:)]) {
[self.m_delegate ICRFunctionBaseView:imageView];
}
}
@end
//
// ICRFunctionEntity.h
// Cruiser
//
// Created by Lili Wang on 15/4/2.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "IBTObject.h"
@interface ICRFunctionEntity : IBTObject
@property (copy, nonatomic) NSString *iconName;
@property (copy, nonatomic) NSString *functionName;
@property (assign, nonatomic) NSInteger bageCount;
@property (assign, nonatomic) NSInteger functionItemTag;
@end
//
// ICRFunctionEntity.m
// Cruiser
//
// Created by Lili Wang on 15/4/2.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "ICRFunctionEntity.h"
@implementation ICRFunctionEntity
@end
//
// ICRFunctionItemControl.h
// Cruiser
//
// Created by Lili Wang on 15/4/1.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import <UIKit/UIKit.h>
//@protocol ICRFuctionItemControlDelegate;
typedef NS_ENUM (NSUInteger, ICRFunctionID) {
kFunctionAnnouncement = 0,
kFunctionTaskManagement,
kFunctionPatrolPlan,
kFunctionMyShop,
kFunctionNavigation,
kFunctionComeShopReg,
kFunctionLeaveShopReg,
kFunctionCreatTask,
kFunctionHandleTask
};
@interface ICRFunctionItemControl : UIControl
//@property (weak, nonatomic) id <ICRFuctionItemControlDelegate> m_delegate;
@property (assign, nonatomic) BOOL highLightWhenTapped;
@property (strong, nonatomic) UIImageView *functionImage;
@property (strong, nonatomic) UILabel *functinNameLabel;
+ (ICRFunctionItemControl *)highLightControl;
@end
//@protocol ICRFuctionItemControlDelegate <NSObject>
//
//@optional
//- (void)singleImageClike:(ICRFunctionItemControl *)imageView;
//
//@end
//
// ICRFunctionItemControl.m
// Cruiser
//
// Created by Lili Wang on 15/4/1.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#define ICRFUNCTION_IMG_TOP_PADDING (25)
#define ICRFUNCTION_IMG_WIDTH (65)
#define ICRFUNCTION_LABEL_HEIGHT (15)
#define ICRFUNCTION_INNER_GAP (7)
#define RIGHT_LINE_WIDTH (0.5)
#import "ICRFunctionItemControl.h"
#import "IBTUIKit.h"
#import "IBTConstants.h"
@interface ICRFunctionItemControl ()
@property(strong, nonatomic) UIImageView *m_rightLine;
@property(strong, nonatomic) UIImageView *m_bottomLine;
@end
@implementation ICRFunctionItemControl
#pragma mark - life Cycle
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self _init];
}
return self;
}
- (void)layoutSubviews {
_functionImage.frame = (CGRect){
.origin.x = (CGRectGetWidth(self.frame) - ICRFUNCTION_IMG_WIDTH)/2,
.origin.y = ICRFUNCTION_IMG_TOP_PADDING,
.size.width = ICRFUNCTION_IMG_WIDTH,
.size.height = ICRFUNCTION_IMG_WIDTH
};
CGSize labelSize = CGSizeMake(CGRectGetWidth(self.frame), ICRFUNCTION_LABEL_HEIGHT);
labelSize = [_functinNameLabel sizeThatFits:labelSize];
_functinNameLabel.frame = (CGRect){
.origin.x = (CGRectGetWidth(self.frame) - labelSize.width)/2,
.origin.y = CGRectGetMaxY(_functionImage.frame) + ICRFUNCTION_INNER_GAP,
.size.width = labelSize.width,
.size.height = ICRFUNCTION_LABEL_HEIGHT
};
_m_rightLine.frame = (CGRect){
.origin.x = CGRectGetWidth(self.frame) - RIGHT_LINE_WIDTH,
.origin.y = 0,
.size.width = RIGHT_LINE_WIDTH,
.size.height = CGRectGetHeight(self.frame)
};
_m_bottomLine.frame = (CGRect){
.origin.x = 0,
.origin.y = CGRectGetHeight(self.frame) - RIGHT_LINE_WIDTH,
.size.width = CGRectGetWidth(self.frame),
.size.height = RIGHT_LINE_WIDTH
};
}
- (void)setHighlighted:(BOOL)highlighted{
[super setHighlighted:highlighted];
if (_highLightWhenTapped) {
self.alpha = highlighted ? IBT_BIN_HIGHLIGHT_ALPHA : 1.0f;
}
}
#pragma mark - Public Method
+ (ICRFunctionItemControl *)highLightControl {
ICRFunctionItemControl *control = [[ICRFunctionItemControl alloc] init];
control.highLightWhenTapped = YES;
return control;
}
#pragma mark - Private Method
- (void)_init {
self.functionImage = [[UIImageView alloc] init];
_functionImage.layer.masksToBounds = YES;
_functionImage.layer.cornerRadius = 65 * 0.5;
_functionImage.backgroundColor = [UIColor clearColor];
[self addSubview:_functionImage];
self.functinNameLabel = [[UILabel alloc] init];
_functinNameLabel.textColor = [UIColor colorWithRed:0.596f green:0.596f blue:0.596f alpha:1.00f];
_functinNameLabel.textAlignment = NSTextAlignmentCenter;
_functinNameLabel.font = [UIFont systemFontOfSize:13];
[self addSubview:_functinNameLabel];
self.m_rightLine = [[UIImageView alloc] init];
_m_rightLine.backgroundColor = [UIColor colorWithRed:0.596f green:0.596f blue:0.596f alpha:1.00f];
[self addSubview:_m_rightLine];
self.m_bottomLine = [[UIImageView alloc] init];
_m_bottomLine.backgroundColor = [UIColor colorWithRed:0.596f green:0.596f blue:0.596f alpha:1.00f];
[self addSubview:_m_bottomLine];
}
@end
//
// ICRCheckBox.h
// Cruiser
//
// Created by Xummer on 15/3/30.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "IBTUIView.h"
typedef NS_ENUM(NSUInteger, CheckBoxBGType) {
kCheckBoxBGWhite = 0,
kCheckBoxBGGray,
};
#define CHECK_BOX_DEFAULT_WIDTH (22.0f)
@interface ICRCheckBox : IBTUIView
@property (assign, nonatomic) BOOL isSelected;
@property (assign, nonatomic) CheckBoxBGType m_eBGType;
- (void)onCheckBoxAction:(id)sender;
@end
//
// ICRCheckBox.m
// Cruiser
//
// Created by Xummer on 15/3/30.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "ICRCheckBox.h"
#import "IBTUIKit.h"
@interface ICRCheckBox ()
@property (strong, nonatomic) UIButton *m_checkBoxBtn;
@property (strong, nonatomic) UIImageView *m_checkBoxBG;
@end
@implementation ICRCheckBox
#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (!self) {
return nil;
}
[self initSubviews];
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
_m_checkBoxBG.origin = (CGPoint){
.x = (self.width - _m_checkBoxBG.width) * .5f,
.y = (self.height - _m_checkBoxBG.height) * .5f
};
_m_checkBoxBtn.frame = self.bounds;
}
#pragma mark - Setter
- (void)setIsSelected:(BOOL)isSelected {
if (_isSelected == isSelected) {
return;
}
_isSelected = isSelected;
_m_checkBoxBtn.selected = _isSelected;
}
- (void)setM_eBGType:(CheckBoxBGType)eBGType {
if (_m_eBGType == eBGType) {
return;
}
_m_eBGType = eBGType;
NSString *nsBGIcon = nil;
switch (_m_eBGType) {
case kCheckBoxBGWhite:
nsBGIcon = @"LoginCheckBox";
break;
case kCheckBoxBGGray:
nsBGIcon = @"GrayCheckBox";
break;
default:
break;
}
self.m_checkBoxBG.image = [UIImage imageNamed:nsBGIcon];
}
#pragma mark - Private Method
- (void)initSubviews {
self.m_checkBoxBG = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"LoginCheckBox"]];
[self addSubview:_m_checkBoxBG];
self.m_eBGType = kCheckBoxBGWhite;
self.m_checkBoxBtn = [IBTUIButton buttonWithType:UIButtonTypeCustom];
[self.m_checkBoxBtn setImage:[UIImage imageNamed:@"LoginCheckMark"]
forState:UIControlStateSelected];
[self.m_checkBoxBtn addTarget:self
action:@selector(onCheckBoxAction:)
forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_m_checkBoxBtn];
}
#pragma mark - Actions
- (void)onCheckBoxAction:(id)sender {
self.isSelected = !_isSelected;
}
@end
//
// ICRLoginContentView.h
// Cruiser
//
// Created by Xummer on 3/30/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import <UIKit/UIKit.h>
@class ICRCheckBox;
@interface ICRLoginContentView : UIView
@property (strong, nonatomic) UITextField *m_cCodeTextF;
@property (strong, nonatomic) UITextField *m_userNameTextF;
@property (strong, nonatomic) UITextField *m_passwordTextF;
@property (strong, nonatomic) ICRCheckBox *m_autoLoginCheckBox;
@property (strong, nonatomic) UIButton *m_loginBtn;
- (instancetype)initWithFrame:(CGRect)frame
showCCode:(BOOL)bNeedShowCCode;
- (void)checkLoginEnable;
- (BOOL)isAutoLogin;
@end
This diff is collapsed.
//
// ICRPlaceholderTextView.h
// Cruiser
//
// Created by Lili Wang on 15/4/7.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ICRPlaceholderTextView : UITextView
@property (strong, nonatomic) NSString *m_placeHolder;
@property (strong, nonatomic) UIColor *m_realTextColor UI_APPEARANCE_SELECTOR;
@property (strong, nonatomic) UIColor *m_placeholderColor UI_APPEARANCE_SELECTOR;
@end
//
// ICRPlaceholderTextView.m
// Cruiser
//
// Created by Lili Wang on 15/4/7.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "ICRPlaceholderTextView.h"
@interface ICRPlaceholderTextView ()
@property (unsafe_unretained, nonatomic, readonly) NSString* realText;
- (void) beginEditing:(NSNotification*) notification;
- (void) endEditing:(NSNotification*) notification;
@end
@implementation ICRPlaceholderTextView
@synthesize m_placeholderColor;
@synthesize m_placeHolder;
@synthesize m_realTextColor;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initObserver];
}
return self;
}
- (void)initObserver {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(beginEditing:)
name:UITextViewTextDidBeginEditingNotification
object:self];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(endEditing:)
name:UITextViewTextDidEndEditingNotification
object:self];
self.m_realTextColor = self.textColor;
self.m_placeholderColor = [UIColor lightGrayColor];
}
#pragma mark -
#pragma mark Setter/Getters
- (NSString *)realText {
return [super text];
}
- (void) setTextColor:(UIColor *)textColor {
if ([self.realText isEqualToString:self.m_placeHolder]) {
if ([textColor isEqual:self.m_placeholderColor]){
[super setTextColor:textColor];
} else {
self.m_realTextColor = textColor;
}
}
else {
self.m_realTextColor = textColor;
[super setTextColor:textColor];
}
}
- (void) setM_placeHolder:(NSString *)am_placeHolder {
if ([self.realText isEqualToString:self.m_placeHolder] && ![self isFirstResponder]) {
self.text = am_placeHolder;
}
if (am_placeHolder != self.m_placeHolder) {
m_placeHolder = am_placeHolder;
}
[self endEditing:nil];
}
- (void)setM_placeholderColor:(UIColor *)am_placeholderColor {
m_placeholderColor = am_placeholderColor;
if ([super.text isEqualToString:self.m_placeHolder]) {
self.textColor = self.m_placeholderColor;
}
}
- (NSString *) text {
NSString* text = [super text];
if ([text isEqualToString:self.m_placeHolder]) return @"";
return text;
}
- (void) setText:(NSString *)text {
if (([text isEqualToString:@""] || text == nil) && ![self isFirstResponder]) {
super.text = self.m_placeHolder;
}
else {
super.text = text;
}
if ([text isEqualToString:self.m_placeHolder] || text == nil) {
self.textColor = self.m_placeholderColor;
}
else {
self.textColor = self.m_realTextColor;
}
}
#pragma mark -
#pragma mark - Observer Actions
- (void) beginEditing:(NSNotification*) notification {
if ([self.realText isEqualToString:self.m_placeHolder]) {
super.text = nil;
self.textColor = self.m_realTextColor;
}
}
- (void) endEditing:(NSNotification*) notification {
if ([self.realText isEqualToString:@""] || self.realText == nil) {
super.text = self.m_placeHolder;
self.textColor = self.m_placeholderColor;
}
}
#pragma mark -
#pragma mark Dealloc
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
//
// ICRSyncCellContentView.h
// Cruiser
//
// Created by Lili Wang on 15/4/30.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "IBTUIView.h"
@interface ICRSyncCellContentView : IBTUIView
- (void)updateItemLabelTitle:(NSString *)strTitle valueLabelText:(NSNumber *)numValue;
@end
This diff is collapsed.
//
// ICRSystemHeaderView.h
// Cruiser
//
// Created by Xummer on 15/4/2.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "IBTUIView.h"
@interface ICRSystemHeaderView : IBTUIView
- (void)updateWithCompanyName:(NSString *)nsCompany
companyIcon:(id)icon
user:(NSString *)nsUserName
code:(NSString *)nsCode;
@end
@interface ICRSystemHeaderView (Configure)
- (void)updateWithUserUtil;
@end
\ No newline at end of file
This diff is collapsed.
//
// IBTRefreshTableView.h
// Cruiser
//
// Created by Xummer on 4/11/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "IBTTableView.h"
#import "IBTScrollViewRefreshDelegate.h"
#import "IBTScrollLoadMoreView.h"
@interface IBTRefreshTableView : IBTTableView
@property (assign, nonatomic) id <IBTScrollViewRefreshDelegate> refreshDelegate;
@property (strong, nonatomic) UIRefreshControl *refreshControl;
@property (strong, nonatomic) IBTScrollLoadMoreView *loadMoreView;
- (void)scrollToTopAnimated:(BOOL)animated;
- (void)scrollToBottomAnimated:(BOOL)animated;
- (void)addRefreshControlWithText:(NSString *)text;
- (void)removeRefreshControl;
- (void)endRefreshWithState:(RefreshState)state;
- (void)addLoadMoreFootWithText:(NSString *)text;
- (void)removeLoadMoreFoot;
- (void)endLoadMoreWithState:(LoadMoreState)state;
- (void)resetLoadMoreFoot;
// call |tableViewDidScroll:| in delegate Method |scrollViewDidScroll:|
- (void)tableViewDidScroll:(UIScrollView *)scrollView;
// call |tableviewDidEndDragging:| in delegate Method |scrollViewDidEndDragging:|
- (void)tableviewDidEndDragging:(UIScrollView *)scrollView;
@end
This diff is collapsed.
//
// IBTScrollLoadMoreView.h
// TableViewRefresh
//
// Created by Xummer on 14-3-27.
// Copyright (c) 2014年 Xummer. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSUInteger, LoadMoreState) {
kLoadStateNormal = 1,
kLoadStateDraging,
kLoadStateLoading,
kLoadStateFinished,
kLoadStateFailed,
kLoadStateNoMore,
};
@interface IBTScrollLoadMoreView : UIView
@property (nonatomic, assign, readonly) LoadMoreState currentState;
@property (nonatomic, strong) UIColor *textColor;
@property (nonatomic, strong) NSString *loadMoreText;
@property (nonatomic, strong) NSString *dragToLoadText;
@property (nonatomic, strong) NSString *loadingText;
@property (nonatomic, strong) NSString *finishedText;
@property (nonatomic, strong) NSString *failedText;
@property (nonatomic, strong) NSString *noMoreText;
- (void)updateState:(LoadMoreState)state;
@end
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment