List of all Iphone and Blackberry Development codes in a one click Iphone,objective C,xcode,blackberry Development,iOS Development

Thursday, April 20, 2017

Utility class for Custom Items in ios

#import Foundation/Foundation.h
#import UIKit/UIKit.h

@interface Util : NSObject
{
    NSString *selectView;
    BOOL isPrepaidCardFlag;
}
-(UILabel *)createLabel:(NSString *)placeholder  x:(float)x y:(float)y l_Width:(float)l_Width l_Height:(float)l_Height l_Color:(UIColor *)l_Color l_Font:(UIFont *)l_Font l_NSTextAlignment:(int)l_NSTextAlignment;
-(UITextField *) createField:(NSString *)placeholder tag:(int)tag x:(float)x y:(float)y t_Width:(float)t_Width t_Height:(float)t_Height t_Color:(UIColor *)t_Color t_Font:(UIFont *)t_Font t_NSTextAlignment:(int)t_NSTextAlignment;
-(void)alertViewShow : (NSString *)_msg withTag:(int)_tag;
- (void)showPopupWithTitle:(NSString *)title
                    mesage:(NSString *)message
              dismissAfter:(NSTimeInterval)interval className:(NSString *)className;
-(NSString *) randomString;
-(CALayer *) borderLine:(float)width height:(float)height;
-(UIView *) buttonLine:(float)x y:(float)y width:(float)width height:(float)height;
- (void)showPopupWithTitleDismis:(NSString *)title
                          mesage:(NSString *)message
                    dismissAfter:(NSTimeInterval)interval className:(NSString *)className;
-(UITextField *) padding:(UITextField *)placeholder t_Height:(float)t_Height;

-(UITextField *) createFieldLightGray:(NSString *)placeholder tag:(int)tag x:(float)x y:(float)y t_Width:(float)t_Width t_Height:(float)t_Height t_Color:(UIColor *)t_Color t_Font:(UIFont *)t_Font t_NSTextAlignment:(int)t_NSTextAlignment;
-(UITextField *) createField2:(NSString *)placeholder tag:(int)tag x:(float)x y:(float)y t_Width:(float)t_Width t_Height:(float)t_Height t_Color:(UIColor *)t_Color t_Font:(UIFont *)t_Font t_NSTextAlignment:(int)t_NSTextAlignment;
@end











#import "Util.h"
#import "UIColor+customColor.h"
#import "Constants.h"
@implementation Util

-(UILabel *)createLabel:(NSString *)placeholder  x:(float)x y:(float)y l_Width:(float)l_Width l_Height:(float)l_Height l_Color:(UIColor *)l_Color l_Font:(UIFont *)l_Font l_NSTextAlignment:(int)l_NSTextAlignment{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, l_Width, l_Height)];
    [label setText:placeholder];
    [label setTextColor:l_Color];
    [label setTextAlignment:l_NSTextAlignment];
    [label setFont:l_Font];
    label.backgroundColor = [UIColor clearColor];
    return label;
}

-(UITextField *) createField:(NSString *)placeholder tag:(int)tag x:(float)x y:(float)y t_Width:(float)t_Width t_Height:(float)t_Height t_Color:(UIColor *)t_Color t_Font:(UIFont *)t_Font t_NSTextAlignment:(int)t_NSTextAlignment
{
    UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(x, y, t_Width, t_Height)];
    field.textAlignment = t_NSTextAlignment;
    field.font = [UIFont systemFontOfSize:18];
    field.clearButtonMode = UITextFieldViewModeWhileEditing;
    //field.backgroundColor = [UIColor whiteColor];
    field.tag = tag;
    UIColor *color = [UIColor colorWithHexString:STRING_GreenWholesaleColor];
    field.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeholder attributes:@{NSForegroundColorAttributeName: color}];
    [field setKeyboardType:UIKeyboardTypeDefault];
    field.textColor = [UIColor colorWithHexString:STRING_GreenDarkColor];

    CALayer *border = [CALayer layer];
    CGFloat borderWidth = 2;
    border.borderColor = [UIColor colorWithHexString:STRING_GreenDarkColor].CGColor;
    border.frame = CGRectMake(0, field.frame.size.height - borderWidth, field.frame.size.width, field.frame.size.height);
    border.borderWidth = borderWidth;
    [field.layer addSublayer:border];
    field.layer.masksToBounds = YES;

    return field;
}

-(UITextField *) createField2:(NSString *)placeholder tag:(int)tag x:(float)x y:(float)y t_Width:(float)t_Width t_Height:(float)t_Height t_Color:(UIColor *)t_Color t_Font:(UIFont *)t_Font t_NSTextAlignment:(int)t_NSTextAlignment
{
    UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(x, y, t_Width, t_Height)];
    field.textAlignment = t_NSTextAlignment;
    field.font = [UIFont systemFontOfSize:18];
    field.clearButtonMode = UITextFieldViewModeWhileEditing;
    //field.backgroundColor = [UIColor whiteColor];
    field.tag = tag;
    UIColor *color = [UIColor colorWithHexString:STRING_GreenWholesaleColor];
    field.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeholder attributes:@{NSForegroundColorAttributeName: color, NSFontAttributeName: [UIFont systemFontOfSize:13]}];
    [field setKeyboardType:UIKeyboardTypeDefault];
    field.textColor = [UIColor colorWithHexString:STRING_GreenDarkColor];
   
    CALayer *border = [CALayer layer];
    CGFloat borderWidth = 2;
    border.borderColor = [UIColor colorWithHexString:STRING_GreenDarkColor].CGColor;
    border.frame = CGRectMake(0, field.frame.size.height - borderWidth, field.frame.size.width, field.frame.size.height);
    border.borderWidth = borderWidth;
    [field.layer addSublayer:border];
    field.layer.masksToBounds = YES;
   
    return field;
}


-(UITextField *) createFieldLightGray:(NSString *)placeholder tag:(int)tag x:(float)x y:(float)y t_Width:(float)t_Width t_Height:(float)t_Height t_Color:(UIColor *)t_Color t_Font:(UIFont *)t_Font t_NSTextAlignment:(int)t_NSTextAlignment
{
    UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(x, y, t_Width, t_Height)];
    field.textAlignment = t_NSTextAlignment;
    field.font = [UIFont systemFontOfSize:18];
    field.clearButtonMode = UITextFieldViewModeWhileEditing;
    //field.backgroundColor = [UIColor whiteColor];
    field.tag = tag;
    UIColor *color = [UIColor lightGrayColor];
    field.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeholder attributes:@{NSForegroundColorAttributeName: color}];
    [field setKeyboardType:UIKeyboardTypeDefault];
    field.textColor = [UIColor blackColor];
   
    CALayer *border = [CALayer layer];
    CGFloat borderWidth = 2;
    border.borderColor = [UIColor lightGrayColor].CGColor;
    border.frame = CGRectMake(0, field.frame.size.height - borderWidth, field.frame.size.width, field.frame.size.height);
    border.borderWidth = borderWidth;
    [field.layer addSublayer:border];
    field.layer.masksToBounds = YES;
   
    return field;
}
-(UILabel *)createLabel1:(NSString *)placeholder  x:(float)x y:(float)y l_Width:(float)l_Width l_Height:(float)l_Height l_Color:(UIColor *)l_Color l_Font:(UIFont *)l_Font l_NSTextAlignment:(int)l_NSTextAlignment{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, l_Width, l_Height)];
    [label setText:placeholder];
    [label setTextColor:l_Color];
    [label setTextAlignment:l_NSTextAlignment];
    [label setFont:l_Font];
    label.backgroundColor = [UIColor clearColor];
    return label;
}
-(UITextField *) padding:(UITextField *)placeholder t_Height:(float)t_Height{
    UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, t_Height)];
    placeholder.leftView = paddingView;
    placeholder.leftViewMode = UITextFieldViewModeAlways;
    return placeholder;
}
-(void)alertViewShow : (NSString *)_msg withTag:(int)_tag {
//    UIAlertController * alert=   [UIAlertController
//                                  alertControllerWithTitle:STRING_AppName
//                                  message:_msg
//                                  preferredStyle:UIAlertControllerStyleAlert];
//    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
//     }];
//    [alert addAction:okAction];
//    UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
//    [vc presentViewController:alert animated:YES completion:nil];
   
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:STRING_AppName
                                                                    message:_msg
                                                                   delegate:self
                                                          cancelButtonTitle:@"Ok"
                                                          otherButtonTitles:nil, nil];
   
                [alertView show];
   
   
}

-(NSString *) randomString {
    NSMutableString *randomString = [NSMutableString stringWithCapacity: 10];
    for (int i=0; i<10 br="" i="">        [randomString appendFormat: @"%C", [@"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" characterAtIndex: arc4random_uniform(36)]];
    }
    return randomString;
}


@end






No comments:

Post a Comment