[UIButton] 밑줄있는 전화걸기 버튼 - iPhone

UIKit에 밑줄이 없어서 커스텀 버튼을 만들어 봤다.

tap시 전화연결 요청여부를 물어보고

누르고 있으면 복사하기 메뉴가 나타남.

// phoneButton.h

#import <UIKit/UIKit.h>

@interface phoneButton : UIButton <UIAlertViewDelegate>

{

}

- (void)fireTouchUpInside;

@end

// phoneButton.m

#import "phoneButton.h"

@implementation phoneButton

- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        // Tap Event

        [self addTarget:self action:@selector(fireTouchUpInside) forControlEvents:UIControlEventTouchUpInside];

        

        // Long Press Event

        UILongPressGestureRecognizer *longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];

        [self addGestureRecognizer:longPressGr];

        [longPressGr release];

        

        // title color

        UIColor* fontColor = [UIColor colorWithRed:81.0/255.0 green:102.0/255.0 blue:145.0/255.0 alpha:1.0];

        [self setTitleColor:fontColor forState:UIControlStateNormal];

        

        // Set Alignment

        self.titleLabel.textAlignment = UITextAlignmentCenter;

    }

    return self;

}

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect

{

    // Drawing code

    [super drawRect:rect];

    CGContextRef context = UIGraphicsGetCurrentContext();

    

    CGContextSetRGBStrokeColor(context, 81.0/255.0, 102.0/255.0, 145.0/255.0, 1.0);

    CGSize textSize = [self.titleLabel.text sizeWithFont:self.titleLabel.font];

    

    CGFloat underLineWidth = textSize.width;

    CGFloat underLineStart = 0.0;

    CGFloat underLineEnd = 0.0;

    switch (self.titleLabel.textAlignment

    {

        default:

        case UITextAlignmentCenter :  

            underLineStart = (self.frame.size.width - underLineWidth)/2;

            break;            

        case UITextAlignmentLeft :

            underLineStart = 0.0;   

            break;

        case UITextAlignmentRight :  

            underLineStart = self.frame.size.width - underLineWidth;

            break;            

    }

    

    underLineEnd = underLineStart + underLineWidth;

    

    CGContextMoveToPoint(context, underLineStart, rect.size.height);

    CGContextAddLineToPoint(context, underLineEnd, rect.size.height);

    CGContextStrokePath(context);

}

- (void)dealloc

{

    [super dealloc];

}

- (BOOL)canBecomeFirstResponder

{

    return YES;

}

- (void) longPress:(UILongPressGestureRecognizer *)gestureRecognizer 

{

    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan

    {

        NSLog(@"%@",[gestureRecognizer view]);

        CGPoint location = [gestureRecognizer locationInView:[gestureRecognizer view]];

        UIMenuController *menuController = [UIMenuController sharedMenuController];

        

        [self becomeFirstResponder];

        [menuController setTargetRect:CGRectMake(location.x, location.y, 0.0f, 0.0f) inView:[gestureRecognizer view]];

        [menuController setMenuVisible:YES animated:YES];

    }

}

- (void)copy:(id)sender 

{

    // called when copy clicked in menu

    NSString* phoneNo = self.titleLabel.text;

    [[UIPasteboard generalPasteboard] setString:phoneNo];

}

(void)setFont:(UIFont*)font

{

    self.titleLabel.font = font;

}

(void)fireTouchUpInside

{

    NSString* phoneNo = self.titleLabel.text;

    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:phoneNo 

                                                    message:@""

                                                   delegate:self

                                          cancelButtonTitle:@"취소" 

                                          otherButtonTitles:@"통화", nil];

    [alert show];

    [alert release];

}

#pragma mark - AlertView Delgate

-(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

    if (buttonIndex ==1) 

    {

        NSString* callString = [NSString stringWithFormat:@"tel:%@", self.titleLabel.text];

        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callString]];

    }

}

@end


http://highslide.com


CheckBox

CheckBox값 설정
- CheckDlgButton(컨트롤명, BOOL값);

CheckBox값 가져오기
- IsDlgButtonChecked(컨트롤명);

test image


nika보드 스킨 잡동사니

오랜만에 고등학교때 만들었던 nika보드의 스킨이 생각나서 구글링을 시작했다.

그렇지만 근 10년전 자료라 그런지 남아있는건 이거하나 .

http://www.happycgi.com/detail.cgi?number=6488

그때는 hodan이라는 닉냄을 사용 했는데..

오랜만에 보니 반갑구나^^;

1 2 3 4 5 6 7