开发者

How to change Background of alert ? and can we change its position?

How to change Background of alert? and can 开发者_如何学运维we change its position? I mean is it possible to display it up or down?

Is there any sample code available?

Thanks in advance.


You cannot through any Apple supported API methods. The advised way of customizing look and feel of a UIAlertView is to create your own.


From the iPhone Human Interface Guidelines:

You can specify the text, the number of buttons, and the button contents in an alert, but you can’t customize the background appearance of the alert itself.

Unless you have a very good reason for wanting to customize the background color or other properties of the alert, don't do it. Your application will clash with the rest of the system, and may be rejected for violating the above-mentioned human interface guidelines. Again, from the iPhone Human Interface Guidelines:

Because users are accustomed to the appearance and behavior of these views, it’s important to use them consistently and correctly in your application.


U can change the color.But i do no about position.Create CustomAlert which inherits from Alert.In drawRect: u can specify color u want in CGContextSetRGBFillColor method. Here is implementation. @implementation CustomAlert

- (id)initWithFrame:(CGRect)frame {
 if (self = [super initWithFrame:frame]) {
  // Initialization code
 }
 return self;
}



// Method which will draw the actual view
- (void)drawRect:(CGRect)rect {
 CGContextRef context=UIGraphicsGetCurrentContext();
 UIColor *color = [UIColor purpleColor];
 const CGFloat *arr= CGColorGetComponents(color.CGColor);
 CGContextSetRGBStrokeColor(context,0, 0, 0, 1.0);
 CGContextSetRGBFillColor(context, arr[0], arr[1], arr[2], 0.85);
 CGContextSetLineWidth(context, 1.0);
 addRoundedRectToPath(context, rect);
 // Drawing final path
CGContextDrawPath(context, kCGPathFill);
}

- (void)dealloc {
 [super dealloc];
}
@end

static void addRoundedRectToPath(CGContextRef context, CGRect rect){
 CGFloat radius = 10;
 CGFloat minx = CGRectGetMinX(rect), midx = CGRectGetMidX(rect), maxx = CGRectGetMaxX(rect);
 CGFloat miny = CGRectGetMinY(rect), midy = CGRectGetMidY(rect), maxy = CGRectGetMaxY(rect);
 CGContextMoveToPoint(context, minx, midy);
 // Add an arc through 2 to 3
 CGContextAddArcToPoint(context, minx, miny, midx, miny, radius);
 // Add an arc through 4 to 5
 CGContextAddArcToPoint(context, maxx, miny, maxx, midy, radius);
 // Add an arc through 6 to 7
 CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, radius);
 // Add an arc through 8 to 9
 CGContextAddArcToPoint(context, minx, maxy, minx, midy, radius);
 CGContextClosePath(context);

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜