PromptMessage.h

#import <UIKit/UIKit.h>

#import <QuartzCore/QuartzCore.h>

 

@interface PromptMessage : UIView {

    UIWindow * keyWindow;

}

 

@property(nonatomic,assign)NSInteger second;

 

- (void)showMessage:(NSString *)msg;

 

- (void)showMessage1:(NSAttributedString *)msg;

 

- (void)showRewardMessage:(NSString *)msg;

 

@end

 

 

#import "PromptMessage.h"

 

@implementation PromptMessage

 

@synthesize second;

 

- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self)

    {

        self.layer.cornerRadius = 5;

        self.backgroundColor =[UIColor blackColor];

        self.alpha = 0.8;

        second = 2;

    }

    return self;

}

 

- (void)showMessage:(NSString *)msg

{

    keyWindow =[UIApplication sharedApplication].keyWindow;

    

    UIView * background = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];

    background.tag = 100;

    [background setBackgroundColor:[UIColor clearColor]];

    [keyWindow addSubview:background];

    

    CGFloat promptHeight = 0.0f;

    

    UILabel * promptMessage = [[UILabel alloc] initWithFrame:CGRectMake(10,10, 240, 0)];

    [promptMessage setTextAlignment:NSTextAlignmentCenter];

    promptMessage.numberOfLines = 0;

    [promptMessage setFont:[UIFont systemFontOfSize:15.0f]];

    [promptMessage setText:msg];

    

    [promptMessage setTextColor:[UIColor whiteColor]];

    promptMessage.backgroundColor = [UIColor clearColor];

    CGSize size = [promptMessage boundingRectWithSize:CGSizeMake(240,0)];

    [promptMessage setFrame:CGRectMake(10,10, 240, size.height+10)];

    [self addSubview:promptMessage];

    

    promptHeight = promptHeight + size.height + 30;

    

    self.frame =CGRectMake(kWidth/2-130,kHeight/2-promptHeight/2, 260,promptHeight);

    [background addSubview:self];

    

    [UIView animateKeyframesWithDuration:0.3 delay:1 options:UIViewKeyframeAnimationOptionCalculationModeLinear animations: ^{

        self.alpha = 0;

    } completion:^(BOOL finished) {

        [background removeFromSuperview];

    }];

}

 

- (void)showMessage1:(NSAttributedString *)msg

{

    keyWindow =[UIApplication sharedApplication].keyWindow;

    

    UIView * background = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];

    background.tag = 100;

    [background setBackgroundColor:[UIColor clearColor]];

    [keyWindow addSubview:background];

    

    CGFloat promptHeight = 0.0f;

    

    UILabel * promptMessage = [[UILabel alloc] initWithFrame:CGRectMake(0,10, 140, 0)];

    [promptMessage setTextAlignment:NSTextAlignmentCenter];

    promptMessage.numberOfLines = 0;

    [promptMessage setFont:[UIFont systemFontOfSize:15.0f]];

    [promptMessage setAttributedText:msg];

    

    promptMessage.backgroundColor = [UIColor clearColor];

    CGSize size = [promptMessage boundingRectWithSize:CGSizeMake(140,0)];

    [promptMessage setFrame:CGRectMake(0,10, 140, size.height+10)];

    [self addSubview:promptMessage];

    

    promptHeight = promptHeight + size.height + 30;

    

    self.frame =CGRectMake(kWidth/2-130+50,kHeight/2-promptHeight/2, 140,promptHeight);

    [background addSubview:self];

    

    [UIView animateKeyframesWithDuration:0.3 delay:1 options:UIViewKeyframeAnimationOptionCalculationModeLinear animations: ^{

        self.alpha = 0;

    } completion:^(BOOL finished) {

        [background removeFromSuperview];

    }];

}

 

 

- (void)showRewardMessage:(NSString *)msg

{

    keyWindow =[UIApplication sharedApplication].keyWindow;

    

    UIView * background = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];

    background.tag = 100;

    [background setBackgroundColor:[UIColor clearColor]];

    [keyWindow addSubview:background];

    

    CGFloat promptHeight = 0.0f;

    

    UILabel * promptMessage = [[UILabel alloc] initWithFrame:CGRectMake(10,10, 240, 0)];

    [promptMessage setTextAlignment:NSTextAlignmentCenter];

    promptMessage.numberOfLines = 0;

    [promptMessage setFont:[UIFont systemFontOfSize:15.0f]];

    [promptMessage setText:msg];

    

    [promptMessage setTextColor:[UIColor whiteColor]];

    promptMessage.backgroundColor = [UIColor clearColor];

    CGSize size = [promptMessage boundingRectWithSize:CGSizeMake(240,0)];

    [promptMessage setFrame:CGRectMake(10,10, 240, size.height+10)];

    [self addSubview:promptMessage];

    

    promptHeight = promptHeight + size.height + 30;

    

    self.frame =CGRectMake(kWidth/2-130,kHeight/2-promptHeight/2, 260,promptHeight);

    [background addSubview:self];

    

    [UIView animateKeyframesWithDuration:0.3 delay:1 options:UIViewKeyframeAnimationOptionCalculationModeLinear animations: ^{

        self.alpha = 0;

    } completion:^(BOOL finished) {

        [background removeFromSuperview];

    }];

}

 

 

@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
解释这段代码#include "config.h" #include "menu.h" #include "hint.h" #include "color.h" #include <stdio.h> #include <stdlib.h> const int optionNum[MENU_NUM] = {4, 7, 4, 6, 6, 4, 4, 4}; // visual prompts for different menus static const char* menuPrompts[MENU_NUM] = {"\ +==============+================+===============+========+\n\ | 1.User Login | 2.User Sign Up | 3.Admin Login | 4.Exit |\n\ +==============+================+===============+========+\n", \ "\ +=========+==========+==========+=========+==========+=======+========+\n\ | 1.Goods | 2.Search | 3.Orders | 4.Users | 5.Delete | 6.Ban | 7.Back |\n\ +=========+==========+==========+=========+==========+=======+========+\n", \ "\ +=========+==========+==============+========+\n\ | 1.Buyer | 2.Seller | 3.Infomation | 4.Back |\n\ +=========+==========+==============+========+\n", \ "\ +=========+=======+==========+=========+===============+========+\n\ | 1.Goods | 2.Buy | 3.Search | 4.Order | 5.Information | 6.Back |\n\ +=========+=======+==========+=========+===============+========+\n", \ "\ +========+=========+==========+=======+=========+========+\n\ | 1.Sell | 2.Goods | 3.Modify | 4.Ban | 5.Order | 6.Back |\n\ +========+=========+==========+=======+=========+========+\n", \ "\ +===============+==========+==========+========+\n\ | 1.Information | 2.Modify | 3.Top Up | 4.Back |\n\ +===============+==========+==========+========+\n", \ "\ +============+========+\n\ | 1.Password | 2.Back |\n\ +============+========+\n", \ "\ +========+=========+===============+========+\n\ | 1.Name | 2.Price | 3.Description | 4.Back |\n\ +========+=========+===============+========+\n"}; static const char* menuNames[MENU_NUM] = {"Main", "Admin", "User", "Buyer", "Seller", "Information", "Modify", "Good"}; /** * @brief print visual prompt message * * @param type menu type */ static void promptMessage(Menu type) { printf("\t\t\t%s%s Menu%s\n", REVERSE, menuNames[type], RESET); printf("%s\n请选择: ", menuPrompts[type]); } int menu(Menu type) { promptMessage(type); char buffer[MAX_LEN]; int res; scanf("%s", buffer); res = atoi(buffer); while (1) { if (res >= 1 && res <= optionNum[type]) break; illegalMessage(); printf("Please try again: "); scanf("%s", buffer); res = atoi(buffer); } return res; }
最新发布
07-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值