ios未读消息图标

Jac*_*opo 8 iphone ios

我想知道iOS中是否有一种标准方法可以为未读消息生成编号的气泡图标,就像iphone和mac的邮件一样.

我不是在谈论应用程序项目上的红点,它使用徽章值,但关于邮箱旁边的蓝色气泡.

当然可以使用coregraphics手动完成,但是很难匹配邮件中使用的标准尺寸和颜色.

Jas*_*gun 11

这里有三种方法可以做到这一点,按顺序排列..

  1. 屏幕截图从您的iPhone拍摄您的邮件应用程序,将图像发送到photoshop,提取蓝点并将其用作应用程序中的图像.要在tableviewcell中使用它,只需设置imageView.image = [UIImage imageName:@"blueDot.png"];

  2. 与#1相同,除了将图像保存为灰度外,这样您就可以使用Quartz并在其上覆盖您自己的颜色.所以你可以把那个点做成你想要的任何颜色.很酷的东西.

  3. 使用Quartz绘制整个事物.它真的不那么难.如果你想要一些代码,请告诉我.

好吧,扭动我的手臂......这是从石英中绘制自己的渐变球体的代码.

创建一个继承自UIView的类.添加以下代码

static float RADIANS_PER_DEGREE=0.0174532925;

-(void) drawInContext:(CGContextRef) context
{

    // Drawing code
    CGFloat radius = self.frame.size.width/2;
    CGFloat start = 0 * RADIANS_PER_DEGREE;
    CGFloat end = 360 * RADIANS_PER_DEGREE;

    CGPoint startPoint = CGPointMake(0, 0);
    CGPoint endPoint = CGPointMake(0, self.bounds.size.height);


    //define our grayscale gradient.. we will add color later
    CGFloat cc[] =
    {
        .70,.7,.7,1,  //r,g,b,a of color1, as a percentage of full on.
        .4,.4,.4,1,  //r,g,b,a of color2, as a percentage of full on.
    };


    //set up our gradient
    CGGradientRef gradient;
    CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
    gradient = CGGradientCreateWithColorComponents(rgb, cc, NULL, sizeof(cc)/(sizeof(cc[0])*4));
    CGColorSpaceRelease(rgb);


    //draw the gray gradient on the sphere


    CGContextSaveGState(context);
    CGContextBeginPath(context);
    CGContextAddArc(context, self.bounds.size.width/2, self.bounds.size.height/2, radius,start,end , 0);
    CGContextClosePath(context);
    CGContextClip(context);

    CGContextAddRect(context, self.bounds);
    CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, kCGGradientDrawsBeforeStartLocation);
    CGGradientRelease(gradient);    

    //now add our primary color.  you could refactor this to draw this from a color property
    UIColor *color = [UIColor blueColor];
    [color setFill];
    CGContextSetBlendMode(context, kCGBlendModeColor);  // play with the blend mode for difference looks
    CGContextAddRect(context, self.bounds);  //just add a rect as we are clipped to a sphere
    CGContextFillPath(context);


    CGContextRestoreGState(context);


}


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

    [self drawInContext:context];
}
Run Code Online (Sandbox Code Playgroud)