我是新手,試圖使用UITextView
來製作類似於iPhone的Notes應用程序的應用程序。 我得到textView
和線路,它工作正常。如何以編程方式在其上添加UINavigationBar和後退按鈕
我的問題是,我想添加一個UINavigationBar
和後退按鈕。 我想在底部添加UIToolBar
,並在其上添加2個toolBarItems如何編程。任何幫助將是一個偉大的推升爲我..
下面是代碼段。
NoteView.h
@interface NoteView : UITextView <UITextViewDelegate,UITabBarControllerDelegate>
{
}
NoteView.m
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor colorWithRed:0.6f green:0.6f blue:1.0f alpha:1.0f];
self.font = [UIFont fontWithName:@"MarkerFelt-Thin" size:20];
self.contentMode = UIViewContentModeRedraw;
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.2f].CGColor);
CGContextSetLineWidth(context, 1.0f);
CGContextBeginPath(context);
NSUInteger numberOfLines = (self.contentSize.height + self.bounds.size.height)/ self.font.leading;
CGFloat baselineOffset = 6.0f;
for (int x = 0; x < numberOfLines; x++) {
CGContextMoveToPoint(context, self.bounds.origin.x, self.font.leading*x + 0.5f + baselineOffset);
CGContextAddLineToPoint(context, self.bounds.size.width, self.font.leading*x + 0.5f + baselineOffset);
}
CGContextClosePath(context);
CGContextStrokePath(context);
}
AddNotesViewController.h
@interface AddNotesViewController : UIViewController <UITextViewDelegate,UITabBarDelegate>
{
NoteView *note;
}
@property (nonatomic, retain) NoteView *note;
@end
AddNotesViewController.m
- (void)loadView
{
[super loadView];
self.note = [[[NoteView alloc] initWithFrame:self.view.bounds] autorelease];
[self.view addSubview:note];
note.delegate = self;
[email protected]"";
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[note setNeedsDisplay];
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
CGRect frame = self.view.bounds;
frame.size.height -= KEYBOARD_HEIGHT;
note.frame = frame;
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
note.frame = self.view.bounds;
}
- (BOOL)textView:(UITextView *)textView
shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text
{
if ([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
return NO;
}
return YES;
}
請告訴我如何以及在哪裏添加導航欄,返回按鈕和工具欄,2個toolBarItems上it.Thanks提前...
重複。 [ButtonOnNav](http://stackoverflow.com/questions/2848055/add-button-to-navigationbar-programatically)&[NavBackButton](http://stackoverflow.com/questions/1441699/uinavigationcontroller-back-button-自定義文本)已經被回答。 通過[鏈接](http://stackoverflow.com/faq#dontask)和[F&Q](http://stackoverflow.com/faq#questions)。 – HDdeveloper
http://stackoverflow.com/questions/13488710/how-to-set-a-picture-programmatically-in-a-navbar/13488781#13488781 – Rajneesh071
是否使用導航控制器或不是 – Rajneesh071