0

我有以下代码:

  - (void)drawRect:(CGRect)rect
{

    [super drawRect:rect];

    float imageHeight = self.image.size.height;

    float imageWidth = self.image.size.width;
    float ratio = imageHeight/imageWidth;
    if(imageHeight> MAX_IMAGE_HEIGHT){
        imageHeight = MAX_IMAGE_HEIGHT;
        imageWidth = imageHeight/ratio;
    }
    if(imageWidth > MAX_IMAGE_WIDTH){
        imageWidth = MAX_IMAGE_WIDTH;
        imageHeight = imageWidth*ratio;
    }
    CGFloat yCoord = (self.bounds.size.height - imageHeight) / 2;
    [self.image drawInRect:CGRectMake(10.0f, yCoord, imageWidth, imageHeight)];
    yCoord = (self.bounds.size.height - MAIN_FONT_SIZE) / 2;
    CGPoint point = CGPointMake(10.0 + imageWidth + 10.0, yCoord);
    [self.title drawAtPoint:point
     forWidth:self.bounds.size.width - (10.0 +imageWidth+20.0)
     withFont:[UIFont systemFontOfSize:MAIN_FONT_SIZE]
     minFontSize:MIN_MAIN_FONT_SIZE
     actualFontSize:NULL

     lineBreakMode:NSLineBreakByTruncatingTail

     baselineAdjustment:UIBaselineAdjustmentAlignBaselines];

}

在编译这个问题时,我关于 drawAtPoint 上的弃用代码并建议我需要更改为 DrawInRect ...但我已经在这里看到了一些帖子,甚至是 SDK 文档,对于我的问题,我不知道如何管理这个...

4

1 回答 1

0

只需使用

- (void)drawInRect:(CGRect)rect withAttributes:(NSDictionary *)attrs

代替

[self.title drawAtPoint:point
 forWidth:self.bounds.size.width - (10.0 +imageWidth+20.0)
 withFont:[UIFont systemFontOfSize:MAIN_FONT_SIZE]
 minFontSize:MIN_MAIN_FONT_SIZE
 actualFontSize:NULL
lineBreakMode:NSLineBreakByTruncatingTail
 baselineAdjustment:UIBaselineAdjustmentAlignBaselines];

大小在矩形中,其余参数作为属性。

于 2013-10-21T10:45:59.737 回答