zoukankan      html  css  js  c++  java
  • 自定义等待视图

    AlertView.h

    #import <UIKit/UIKit.h>
    
    @interface AlertView : UIView
    
    @property (strong, nonatomic) UILabel *messageLabel;
    @end

    AlertView.m

    #import "AlertView.h"
    
    @interface AlertView()
    {
        UIActivityIndicatorView *activityIndicatorView;
    }
    @end
    
    @implementation AlertView
    @synthesize messageLabel;
    
    -(id) init
    {
        CGRect viewRect = CGRectMake(0, 0, 120, 120);
        self = [super initWithFrame:viewRect];
        
        if (self) {
            [self initSetup];
            [self initActivityIndicatorView];
            [self initMessage];
        }
        return self;
    }
    
    -(void) initSetup
    {
        CGRect mainRect = [[UIScreen mainScreen] bounds];
        self.backgroundColor = [UIColor blackColor];
        self.center = CGPointMake(mainRect.size.width / 2, mainRect.size.height / 2);
        self.alpha = 0.6;
        [[self layer] setCornerRadius: 15.0];
    }
    
    -(void) initActivityIndicatorView
    {
        CGRect frameRect = self.frame;
        activityIndicatorView = [[UIActivityIndicatorView alloc]
                                 initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        activityIndicatorView.center = CGPointMake(frameRect.size.width / 2, frameRect.size.height / 2 - 10);
        [self addSubview:activityIndicatorView];
        [activityIndicatorView startAnimating];
    }
    
    -(void) initMessage
    {
        messageLabel = [[UILabel alloc]init];
        messageLabel.frame = CGRectMake(0, 0, self.frame.size.width - 15, 20);
        messageLabel.font = [UIFont fontWithName:@"Arial-Bold" size:15];
        messageLabel.textColor = [UIColor whiteColor];
        messageLabel.center =  CGPointMake(self.frame.size.width / 2, self.frame.size.height -20);
        messageLabel.text = @"Please Wait...";
        [self addSubview:messageLabel];
    }
    
    @end

    使用:

    #import "ViewController.h"
    #import "AlertView.h"
    
    @interface ViewController ()
    {
        AlertView *alertView;
    }
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        alertView = nil;
    }
    
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        if (alertView) {
            [alertView removeFromSuperview];
            alertView = nil;
        }
        else
        {
            alertView = [[AlertView alloc]init];
            [self.view addSubview:alertView];
        }
    }
  • 相关阅读:
    C# 请求API(一次登陆,多次请求)
    C# WebAPI 跨域问题Cors
    正则表达式校验YYYYMMDD
    C# 通过Smtp 完成系统发送邮件
    C# Log4Net 记录项目日志
    C# 自定义Attribute
    C#泛型
    SQL从数据库导出数据到EXCEL换行的问题解决方法
    C# 在MVC 中把DataTable中的数据导出到Excel
    闹心的CSDN
  • 原文地址:https://www.cnblogs.com/code-style/p/4032348.html
Copyright © 2011-2022 走看看