计算机

//

//  ViewController.m

#import "SDAutoLayout.h"

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong) UITextView              *textView;

@property (nonatomic, strong) UITextView              *textViewBottom;

@property (nonatomic, copy)  NSString          *string;

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    floatmagin =10;


    UITextView*text = [selfreturnTextView];

    self.textView= text;

    text.sd_layout.topSpaceToView(self.view,60).leftSpaceToView(self.view, magin).rightSpaceToView(self.view,100).heightRatioToView(self.view,0.4);


    text = [selfreturnTextView];

    self.textViewBottom = text;

    text.sd_layout.topSpaceToView(self.textView, magin).leftSpaceToView(self.view, magin).rightSpaceToView(self.view, magin).bottomSpaceToView(self.view,50);


    UIButton*button = [selfreturnButton:@"提交"tag:1];

    button.sd_layout.rightSpaceToView(self.view, magin).topSpaceToView(self.textView, -180).widthIs(80).heightIs(36);


    UIButton*button2 = [selfreturnButton:@"复制"tag:2];

    button2.sd_layout.rightEqualToView(button).topSpaceToView(button,10).widthIs(80).heightIs(36);


    UIButton*button3 = [selfreturnButton:@"清空"tag:3];

    button3.sd_layout.rightEqualToView(button).topSpaceToView(button2,10).widthIs(80).heightIs(36);


    UIButton*button4 = [selfreturnButton:@"返回"tag:4];

    button4.sd_layout.rightEqualToView(button).topSpaceToView(button3,10).widthIs(80).heightIs(36);

}

- (void)touchesBegan:(NSSet *)toucheswithEvent:(UIEvent*)event

{

    [self.textView resignFirstResponder];

    [self.textViewBottom resignFirstResponder];

}

- (void)buttonClick:(UIButton*)sender

{

    switch(sender.tag) {

        case1:

        {

            [self.textView resignFirstResponder];

            NSString*str =self.textView.text;

            NSArray *array = [str componentsSeparatedByString:@"\n"];

            str =@"";

            for(inti =0; i < array.count-1; i++) {

                floatnum1 = [array[i]floatValue];

                floatnum2 = [array[i +1]floatValue];

                floatvalue =fabsf(num1 - num2) / num1;

                if(num1 < num2 && str.length==0) {//先升

                    str =@"================";

                }

                if(num1 >1000|| num2 >1000) {

                    str = [strstringByAppendingFormat:@"%.0f %.0f=%.2f",num1,num2,value];

                }else{

                    str = [strstringByAppendingFormat:@"%.2f %.2f=%.2f",num1,num2,value];

                }

                if(num1 < num2) {

                    str = [strstringByAppendingString:@"\n"];

                }else{

                    str = [strstringByAppendingString:@"        "];

                }

            }

            self.textViewBottom.text= str;

        }

            break;

        case2:

        {

            UIPasteboard *past = [UIPasteboard generalPasteboard];

            past.string=self.textViewBottom.text;

        }

            break;

        case3:

        {

            self.string=self.textView.text;

            self.textView.text=@"";

        }

            break;

        case4:

        {

            self.textView.text=self.string;

        }

            break;

        default:

            break;

    }

}

- (UITextView *)returnTextView

{

    UITextView *text = [UITextView new];

    text.sd_cornerRadius =@10;

    text.font = [UIFont systemFontOfSize:18];

    text.backgroundColor = [UIColor groupTableViewBackgroundColor];

    text.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

    [self.viewaddSubview:text];

    returntext;

}

- (UIButton *)returnButton:(NSString *)title tag:(NSInteger)tag

{

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    button.tag= tag;

    button.titleLabel.font = [UIFont systemFontOfSize:16];

    button.sd_cornerRadiusFromHeightRatio =@0.5;;

    button.backgroundColor = [UIColor cyanColor];

    [buttonsetTitle:title forState:UIControlStateNormal];

    [buttonaddTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];

    [self.viewaddSubview:button];

    returnbutton;

}

@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容