2010년 2월 22일 월요일

ruby Time format

쓸 때마다 까먹는...

Formats time according to the directives in the given format string. Any text not listed as a directive will be passed through to the output string.

Format meaning:

  %a - The abbreviated weekday name (``Sun'')
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%H - Hour of the day, 24-hour clock (00..23)
%I - Hour of the day, 12-hour clock (01..12)
%j - Day of the year (001..366)
%m - Month of the year (01..12)
%M - Minute of the hour (00..59)
%p - Meridian indicator (``AM'' or ``PM'')
%S - Second of the minute (00..60)
%U - Week number of the current year,
starting with the first Sunday as the first
day of the first week (00..53)
%W - Week number of the current year,
starting with the first Monday as the first
day of the first week (00..53)
%w - Day of the week (Sunday is 0, 0..6)
%x - Preferred representation for the date alone, no time
%X - Preferred representation for the time alone, no date
%y - Year without a century (00..99)
%Y - Year with century
%Z - Time zone name
%% - Literal ``%'' character

t = Time.now
t.strftime("Printed on %m/%d/%Y") #=> "Printed on 04/09/2003"
t.strftime("at %I:%M%p") #=> "at 08:56AM"

http://ruby-doc.org/core/classes/Time.html#M000298

2010년 2월 12일 금요일

MFMailComposeViewController


app 안에서 메일을 보낼 때.

UApplication의 openURL 을 이용하면 현재 프로그램이 종료되고, 메일 프로그램이 실행되므로,
어플 안에서 메일만 보내고자 한다면 이걸 사용해야 하는 듯.

-canSendMail  로 메일발송가능한 장비인지 먼저 확인.

뷰를 보여주는건 보통 presentModalViewController:animated:  로 처리하면 된다.

제목, 수신, cc, bcc, 본문, 파일첨부를 위한 메쏘드들이 있다.

*주의사항
메일 인터페이스가 표시된 이후엔, 코드로 내용에 손을 대선 안된다는거.
메일이 잘 발송되었는지도 보장하지 않는다는거. (보낼 편지함에 남을 수도 있고, 보내졌을 수도 있고...)

delegate 는
MFMailComposeViewControllerDelegate

– mailComposeController:didFinishWithResult:error:
메일작성창이 사라질때 호출되고, 결과를 반환

결과 상수
MFMailComposeResult

MFMailComposeResultCancelled 사용자 취소
MFMailComposeResultSaved 임시보관함에 저장.
MFMailComposeResultSent 발송됨 (보낼편지함에 저장)
MFMailComposeResultFailed 에러

Framework: MessageUI

참고
http://developer.apple.com/iphone/library/documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html

http://developer.apple.com/iphone/library/documentation/MessageUI/Reference/MFMailComposeViewControllerDelegate_protocol/Reference/Reference.html#//apple_ref/occ/intf/MFMailComposeViewControllerDelegate

2010년 2월 9일 화요일

ActionMailer 제목 인코딩.

ActionMailer 에서
제목 인코딩이 quoted_printable 이 기본이고 base64로 바꿀 수 있는 방법이 없더라.

그래서...

require "base64"

encoded = Base64.encode64(old_subject)
subject "=?UTF-8?B?" + encoded + "?="



메일 서비스에 따라 quoted_printable 로 인코딩 되었을 때
제목에 스페이스가 _ 로 표시되는 문제가 있어서...


UIAlertView 에 텍스트필드 넣기.

    UIAlertView* dialog = [[[UIAlertView alloc] init] retain];
    [dialog setDelegate:self];
    [dialog setTitle:@"Enter Name"];
    [dialog setMessage:@" "];
    [dialog addButtonWithTitle:@"Cancel"];
    [dialog addButtonWithTitle:@"OK"];
   
    UITextField *nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
    [nameField setBackgroundColor:[UIColor whiteColor]];
    [dialog addSubview:nameField];
    CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 100.0);
    [dialog setTransform: moveUp];
    [dialog show];
    [dialog release];
    [nameField release];


참고
http://stackoverflow.com/questions/376104/uitextfield-in-uialertview-on-iphone-how-to-make-it-responsive

2010년 2월 4일 목요일

UITableView 의 Grouped Style 의 배경색.

UITableView 의 style을 grouped로 했을 때 나오는 배경을

어떻게 지정하는지 계속 궁금했는데,

[UIColor groupTableViewBackgroundColor] 로 쓰면 된다.

UIColor 레퍼런스를 보면 기본색상들을 클래스 메쏘드로 제공하고 있다.


UITextView Rounded Rect 입히기

UITextView도 UITextField 처럼 quartz를 이용해서 rounded rect를 적용할 수 있다.

// framework 에 QuartzCore 추가.

#import <QuartzCore/QuartzCore.h>

//...

// 아래 textView는 IB에서 설정해둔것.

//The rounded corner part, where you specify your view's corner radius:
textView.layer.cornerRadius = 10;
textView.clipsToBounds = YES;   




참고
http://stackoverflow.com/questions/1824463/how-to-style-uitextview-to-like-rounded-rect-text-field