首页 > 代码库 > ISO UITextView 做意见反馈

ISO UITextView 做意见反馈

应该说每一个都有意见反馈,很简单的功能,镔哥直接做个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 {

    [superviewDidLoad];

    [self greatNav];

    [selfgreatFeedBackView];

    // Do any additional setup after loading the view, typically from a nib.

}


//创建输入文本框

-(void) greatFeedBackView

{

    self.textView= [[UITextViewalloc]initWithFrame:CGRectMake(10,65, 300, 250)];//初始化大小并自动释放

    self.textView.layer.borderColor = [[UIColor blackColor]CGColor];//设置文本框的字体颜色

    self.textView.layer.borderWidth = 0.6;

    self.textView.font = [UIFontfontWithName:@"Arial"size:17.0];

    self.textView.delegate =self;//设置委托方法

    self.textView.backgroundColor = [UIColorwhiteColor];

     self.textView.text =@"";//设置它显示的内容

    self.textView.returnKeyType = UIReturnKeyDefault;//返回键的类型

    self.textView.keyboardType = UIKeyboardTypeDefault;//键盘类型

    

    self.textView.scrollEnabled =YES;//是否可以拖动

    self.textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;

     [self.viewaddSubview: self.textView];

    UIToolbar * topView = [[UIToolbaralloc]initWithFrame:CGRectMake(0,0, 320, 30)];

    

    [topView setBarStyle:UIBarStyleBlack];

    

    UIBarButtonItem * canelButton = [[UIBarButtonItemalloc]initWithTitle:@"取消"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(dismissKeyBoard)];

    

    UIBarButtonItem * btnSpace = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:selfaction:nil];

    

    doneButton = [[UIBarButtonItemalloc]initWithTitle:@"发送"style:UIBarButtonItemStyleDonetarget:selfaction:@selector(dismissKeyBoard)];

    

    NSArray * buttonsArray = [NSArrayarrayWithObjects:canelButton,btnSpace,doneButton,nil];

    

    

    

    [topView setItems:buttonsArray];

    

    [self.textViewsetInputAccessoryView:topView];


    

    

}

#pragma mark-TextView的代理

-(void)dismissKeyBoard


{

    


     [self.textViewresignFirstResponder];

    UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"已经收录,感谢你的反馈"delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil,nil];

    [alert show];

  

    

}

#pragma marks -- UIAlertViewDelegate -- 

//AlertView的取消按钮的事件


-(void)alertViewCancel:(UIAlertView *)alertView

{

   

}


//导航栏设置

-(void)greatNav

{

    self.view.backgroundColor = [UIColorwhiteColor];

    UINavigationBar *navbar = [[UINavigationBaralloc]initWithFrame:CGRectMake(0,0, 320, 64)];

    [navbar setBackgroundColor:[UIColorclearColor]];

    // 3.设置导航栏文字的主题

    NSShadow *shadow=[[NSShadowalloc]init];

    [shadow setShadowOffset:CGSizeMake(0,0)];

    [navbar setTitleTextAttributes:@{

                                  NSForegroundColorAttributeName : [UIColorblackColor],

                                  NSShadowAttributeName : shadow

                                  }];


    // 设置状态栏样式

    [UIApplicationsharedApplication].statusBarStyle =UIStatusBarStyleLightContent;

    //创建一个导航栏集合

    UINavigationItem *navItem = [[UINavigationItemalloc]initWithTitle:@"意见反馈"];

    //在这个集合Item中添加标题,按钮

    //style:设置按钮的风格,一共有三种选择

    //action@selector:设置按钮的点击事件

    leftButton = [[UIBarButtonItemalloc]initWithTitle:@"返回"style:UIBarButtonItemStyleDonetarget:selfaction:@selector(clickLeftButton)];

    //创建一个右边按钮

    

//两种方式任选一种

//      rightButton = [[UIBarButtonItem alloc] initWithTitle:@"右边" style:UIBarButtonItemStyleDone target:self action:@selector(clickRightButton)];

//    rightButton.tintColor = [UIColor greenColor];

//    rightButton.enabled = NO;

    sendButon = [[UIButtonalloc]initWithFrame:CGRectMake(280,30, 38, 30)];

    [sendButonsetTitle:@"发送"forState:UIControlStateNormal];

    [sendButonsetTitleColor:[UIColorgreenColor] forState:UIControlStateNormal];

    [sendButonaddTarget:selfaction:@selector(dismissKeyBoard)forControlEvents:UIControlEventTouchUpInside];

    //[sendButon setBackgroundColor:[UIColor blueColor]];

    [navbar addSubview:sendButon];

    //把左右两个按钮添加到导航栏集合中去

    [navItem setLeftBarButtonItem:leftButton];

   // [navItem setRightBarButtonItem:rightButton];


    

    //把导航栏集合添加到导航栏中,设置动画关闭

    [navbar pushNavigationItem:navItemanimated:NO];

    [self.viewaddSubview:navbar];

    self.navigationController.title =@"意见反馈";

}


-(void) clickRightButton

{

    

    [selfshowDialog:@"点击了导航栏右边按钮"];

    rightButton.enabled =YES;

    

  

    // [self.navigationController pushViewController:second animated:YES];

    //在没有导航栏根视图必须要用模态

    //[self presentViewController:second animated:YES completion:nil];

    

}


-(void) clickLeftButton

{

    [selfshowDialog:@"点击了导航栏左边按钮"];

}

-(void)showDialog:(NSString *)str

{

    UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:@"这是一个对话框"message:str delegate:selfcancelButtonTitle:@"确定"otherButtonTitles: nil];

    [alert show];

    

}



ISO UITextView 做意见反馈