提示信息功能,显示成功或者失败的弹框,代码简单好用。

 //   NBLoadSuccessView.h// 一个打钩的弹框和一个打叉的弹框,后者继承前者,一共四个文件,拷贝创建即可
#import <UIKit/UIKit.h>

@interface NBLoadSuccessView : UIView

// the message showed in the view
@property (nonatomic, copy) NSString *message;
// combined property ‘message‘ to use
- (void)showInView:(UIView *)view;

// suggested that afference a controller‘s view
+ (void)showMessage:(NSString *)message InView:(UIView *)view;
- (void)showMessage:(NSString *)message InView:(UIView *)view;

@end
//
//  NBLoadSuccessView.m

#import "NBLoadSuccessView.h"

@interface NBLoadSuccessView ()
@property (nonatomic, weak) UILabel *label;
@end
@implementation NBLoadSuccessView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {

        [self setup];

    }
    return self;

}

- (id)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder]) {

        [self setup];
    }

    return self;
}

- (void)setup
{
    self.alpha = 0;

    UILabel *label = [[UILabel alloc] init];

    label.textAlignment = NSTextAlignmentCenter;
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont systemFontOfSize:16];

    [self addSubview:label];
    self.label = label;
}

- (void)layoutSubviews
{
    [super layoutSubviews];

    CGFloat padding = 10;
    CGFloat labelW = self.bounds.size.width;
    CGFloat labelH = 16;
    CGFloat labelX = 0;
    CGFloat labelY =self.bounds.size.height - labelH - padding;
    self.label.frame = CGRectMake(labelX, labelY, labelW, labelH);
}

- (void)drawRect:(CGRect)rect
{
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGFloat centerX = rect.size.width * 0.5;
    CGFloat centerY = rect.size.height * 0.5;
    CGContextMoveToPoint(ctx, centerX - 15, centerY - 15);
    CGContextAddLineToPoint(ctx, centerX, centerY);
    CGContextAddLineToPoint(ctx, centerX + 25, centerY - 25);

    [[UIColor whiteColor] set];
    CGContextSetLineWidth(ctx, 8);
    CGContextSetLineCap(ctx, kCGLineCapRound);
    CGContextSetLineJoin(ctx, kCGLineJoinRound);
    CGContextStrokePath(ctx);
}

- (void)setMessage:(NSString *)message
{
    _message = message;

    self.label.text = message;
}

- (void)showMessage:(NSString *)message InView:(UIView *)view
{

    self.message = message;

    [self showInView:view];

//    [view addSubview:self];
//    self.frame = [self fixFrame];
//    [self dismissView];
}

- (void)showInView:(UIView *)view
{

    [view addSubview:self];

    self.frame = [self fixFrame];

    [self dismissView];
}

+ (void)showMessage:(NSString *)message InView:(UIView *)view
{
    NBLoadSuccessView *loadSuccessView = [[self alloc] init];
//    loadSuccessView.message = message;

    [loadSuccessView showMessage:message InView:view];

//    [view addSubview:loadSuccessView];
//    loadSuccessView.frame = [loadSuccessView fixFrame];
//    [loadSuccessView dismissView];
}

- (CGRect)fixFrame
{
    CGFloat frameW = 120;
    CGFloat frameH = 100;
    CGFloat frameX = self.superview.bounds.size.width * 0.5 - frameW * 0.5;
    CGFloat frameY = self.superview.bounds.size.height * 0.4 - frameH * 0.5;
    return  CGRectMake(frameX, frameY, frameW, frameH);
}

- (void)dismissView
{
    [UIView animateWithDuration:0.5 animations:^{
        self.alpha = 0.3;
    }];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:0.5 animations:^{
            self.alpha = 0;
        } completion:^(BOOL finished) {
            [self removeFromSuperview];
        }];
    });

}

@end
//
//  NBLoadFailView.h

#import "NBLoadSuccessView.h"

@interface NBLoadFailView : NBLoadSuccessView

@end
//
//  NBLoadFailView.m

#import "NBLoadFailView.h"

@implementation NBLoadFailView

- (void)drawRect:(CGRect)rect
{

    CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGFloat centerX = rect.size.width * 0.5;
    CGFloat centerY = rect.size.height * 0.4;
    CGContextMoveToPoint(ctx, centerX - 15, centerY - 15);
    CGContextAddLineToPoint(ctx, centerX + 15, centerY + 15);
    CGContextMoveToPoint(ctx, centerX + 15, centerY - 15);
    CGContextAddLineToPoint(ctx, centerX - 15, centerY + 15);

    [[UIColor whiteColor] set];
    CGContextSetLineWidth(ctx, 8);
    CGContextSetLineCap(ctx, kCGLineCapRound);
    CGContextSetLineJoin(ctx, kCGLineJoinRound);
    CGContextStrokePath(ctx);

}

@end
时间: 2024-10-11 00:56:27

提示信息功能,显示成功或者失败的弹框,代码简单好用。的相关文章

写入cookie后只显示一次的DIV提示框代码

<script type="text/javascript"> function cookiesave(n, v, mins, dn, path){ if(n) { if(!mins) mins = 365 * 24 * 60; if(!path) path = "/"; var date = new Date(); date.setTime(date.getTime() + (mins * 60 * 1000)); var expires = &quo

移动端(H5)弹框组件--简单--实用--不依赖jQuery

俗话说的好,框架是服务与大家的,包含的功能比较多,代码多.在现在追求速度的年代.应该根据自己的需求去封装自己所需要的组件. 下边就给大家介绍一下自己封装的一个小弹框组件,不依赖与jQuery,代码少,适用于一般移动端小项目. 这个插件名称:MobileUi 包含功能:弹框,正在加载,tips1.5秒消失,清除正在加载. 如图:    接下来我来告诉大家怎么用吧!! 第一步:配置<meta name="viewport" content="width=device-wid

二级弹框代码

using UnityEngine; using System.Collections; /// <summary> /// Pop button. /// </summary> public class BtnBop : MonoBehaviour { //设置对话框 public GameObject mSettingDlg; public POP_DLG_TYPE mCurDlgType=POP_DLG_TYPE.DLG_NONE; //4 pop up button //p

弹框代码

package com.edu.demo; import java.util.*;import java.io.*; import javax.swing.JFileChooser;import javax.swing.JOptionPane; public class ReadFileUsingJFileChooser { /**     * @param args     * @throws Exception      */    public static void main(Strin

Android AlertDialog 各种弹框代码

1.消息框 btn01.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder ab = new AlertDialog.Builder(BtnActivity.this); ab.setTitle("消息标题"); ab.setMessage("提示内容提示内容提示内容"); ab.setPositiveB

考拉Android统一弹框

作者:钱成杰 背景 在快速开发的背景下,经历了n个版本后的考拉Android App中已经存在了各种各样看似相同却各有差别的弹框样式.其中包括系统弹框和自定义弹框,并且在线上时常会出现IllegalArgumentException的异常,而现有的解决方法是通过工具类来保护调用show和dismiss方法,这种方式效率不高,而且覆盖不全,开发过程中容易遗漏.另外现有的Builder方式的弹框构造工具虽然功能强大,能构造各种弹框,但是使用复杂,样式逻辑耦合,使用成本太高.于是,便需要一款样式统一.

CSS3新vw, vh单位与纯CSS定位的弹框屏幕居中效果实例页面

在css中vw和vh分别代表所占的百分比,可以设置最外部的容器的宽高,但是都要结合百分比一起使用. 展示 回到相关文章 ? 图片宽度(目前1024像素): 128  1024 点击我出现图片弹框 代码CSS代码:.dialog_container {    display: none;    width: 100%;    width: 100vw;    height: 100%;    height: 100vh;    background-color: rgba(0,0,0,.35); 

下载不含数据EXCEL的固定表头模版(标准EXCEL只含有列头),然后上传EXCEL.显示成功和上传失败的EXCEL连接

<div id="import" runat="server" visible="false"> Step1:<asp:HyperLink ID="HyperLink1" NavigateUrl="~/CommonTemplate/设备清单模版.xlsx" runat="server">下载模版</asp:HyperLink><br />

sql server2008配置管理工具服务显示远程过程调用失败

SQL SERVER2008配置管理工具服务显示远程过程调用失败 前两天,装了VS2012后,打开SQL2008配置管理工具,发现SQL服务名称里什么也没有,只有一个提示:(如图) 上网搜了,试了很多方法,像什么把windows\system32\wbem下的framedyn.dll复制到system32目录下,还有照一个老外说的,下什么更新补丁,都没用!! 想重装SQL2008,结果运行安装程序,变成了英文版(以前装显示的是中文的),而且安装根目录选不了!巨想死! 万念俱灰下,打开360,卸载