簡體   English   中英

drawAtPoint不推薦使用iOS 7

[英]drawAtPoint deprecated iOS 7

我有以下代碼:

  - (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文檔,對於我的問題,我也不知道該如何管理...

只需使用

- (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];

大小在rect中,其余參數作為屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM