应该说每一个都有意见反馈,很简单的功能,镔哥直接做个demo用来以后直接拉用,这么简单的功能,在做项目的时候就不用多考虑了,这样会加快项目进展。
//
// ViewController.m
// feedback
//
// Created by apple on 14/12/5.
// Copyright (c) 2014年 youdianshang. All rights reserved.
//
#import "ViewController.h"
@interface
ViewController ()<UITextViewDelegate,UIAlertViewDelegate>
{
UIBarButtonItem *leftButton ;
UIBarButtonItem *rightButton;
UIBarButtonItem * doneButton;
UIButton *sendButon;
}
@property (nonatomic,
retain) UITextView *textView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super
viewDidLoad];
[self greatNav];
[self
greatFeedBackView];
// Do any additional setup after loading the view, typically from a nib.
}
//创建输入文本框
-(void) greatFeedBackView
{
self.textView= [[UITextView
alloc]initWithFrame:CGRectMake(10,
65,
300, 250)];//初始化大小并自动释放
self.textView.layer.borderColor
= [[UIColor blackColor]
CGColor];//设置文本框的字体颜色
self.textView.layer.borderWidth
= 0.6;
self.textView.font = [UIFont
fontWithName:@"Arial"
size:17.0];
self.textView.delegate =
self;//设置委托方法
self.textView.backgroundColor = [UIColor
whiteColor];
self.textView.text =
@"";//设置它显示的内容
self.textView.returnKeyType
= UIReturnKeyDefault;//返回键的类型
self.textView.keyboardType
= UIKeyboardTypeDefault;//键盘类型
self.textView.scrollEnabled =
YES;//是否可以拖动
self.textView.autoresizingMask
= UIViewAutoresizingFlexibleHeight;
[self.view
addSubview: self.textView];
UIToolbar * topView = [[UIToolbar
alloc]initWithFrame:CGRectMake(0,
0, 320,
30)];
[topView setBarStyle:UIBarStyleBlack];
UIBarButtonItem * canelButton = [[UIBarButtonItem
alloc]initWithTitle:@"取消"
style:UIBarButtonItemStylePlain
target:self
action:@selector(dismissKeyBoard)];
UIBarButtonItem * btnSpace = [[UIBarButtonItem
alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:self
action:nil];
doneButton = [[UIBarButtonItem
alloc]initWithTitle:@"发送"
style:UIBarButtonItemStyleDone
target:self
action:@selector(dismissKeyBoard)];
NSArray * buttonsArray = [NSArray
arrayWithObjects:canelButton,btnSpace,doneButton,nil];
[topView setItems:buttonsArray];
[self.textView
setInputAccessoryView:topView];
}
#pragma mark-TextView的代理
-(void)dismissKeyBoard
{
[self.textView
resignFirstResponder];
UIAlertView *alert = [[UIAlertView
alloc]initWithTitle:@"提示"
message:@"已经收录,感谢你的反馈"
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:nil,
nil];
[alert show];
}
#pragma marks -- UIAlertViewDelegate --
//AlertView的取消按钮的事件
-(void)alertViewCancel:(UIAlertView *)alertView
{
}
//导航栏设置
-(void)greatNav
{
self.view.backgroundColor = [UIColor
whiteColor];
UINavigationBar *navbar = [[UINavigationBar
alloc]initWithFrame:CGRectMake(0,
0, 320,
64)];
[navbar setBackgroundColor:[UIColor
clearColor]];
// 3.设置导航栏文字的主题
NSShadow *shadow=[[NSShadow
alloc]init];
[shadow setShadowOffset:CGSizeMake(0,
0)];
[navbar setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor
blackColor],
NSShadowAttributeName : shadow
}];
//
设置状态栏样式
[UIApplication
sharedApplication].statusBarStyle =
UIStatusBarStyleLightContent;
//创建一个导航栏集合
UINavigationItem *navItem = [[UINavigationItem
alloc]initWithTitle:@"意见反馈"];
//在这个集合Item中添加标题,按钮
//style:设置按钮的风格,一共有三种选择
//action:@selector:设置按钮的点击事件
leftButton = [[UIBarButtonItem
alloc]initWithTitle:@"返回"
style:UIBarButtonItemStyleDone
target:self
action:@selector(clickLeftButton)];
//创建一个右边按钮
//两种方式任选一种
// rightButton = [[UIBarButtonItem alloc] initWithTitle:@"右边" style:UIBarButtonItemStyleDone target:self action:@selector(clickRightButton)];
// rightButton.tintColor = [UIColor greenColor];
// rightButton.enabled = NO;
sendButon = [[UIButton
alloc]initWithFrame:CGRectMake(280,
30,
38, 30)];
[sendButon
setTitle:@"发送"
forState:UIControlStateNormal];
[sendButon
setTitleColor:[UIColor
greenColor] forState:UIControlStateNormal];
[sendButon
addTarget:self
action:@selector(dismissKeyBoard)
forControlEvents:UIControlEventTouchUpInside];
//[sendButon setBackgroundColor:[UIColor blueColor]];
[navbar addSubview:sendButon];
//把左右两个按钮添加到导航栏集合中去
[navItem setLeftBarButtonItem:leftButton];
// [navItem setRightBarButtonItem:rightButton];
//把导航栏集合添加到导航栏中,设置动画关闭
[navbar pushNavigationItem:navItem
animated:NO];
[self.view
addSubview:navbar];
self.navigationController.title =
@"意见反馈";
}
-(void) clickRightButton
{
[self
showDialog:@"点击了导航栏右边按钮"];
rightButton.enabled =
YES;
// [self.navigationController pushViewController:second animated:YES];
//在没有导航栏根视图必须要用模态
//[self presentViewController:second animated:YES completion:nil];
}
-(void) clickLeftButton
{
[self
showDialog:@"点击了导航栏左边按钮"];
}
-(void)showDialog:(NSString *)str
{
UIAlertView *alert = [[UIAlertView
alloc] initWithTitle:@"这是一个对话框"
message:str delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles: nil];
[alert show];
}