簡體   English   中英

如何制作這類徽章?

[英]How to create these kind of badges?

我繪制了這個原型的草圖: http : //dl.dropbox.com/u/3630641/3-%20Todolist%20Main.jpg

左邊的數字是項目優先級,列表是可重新排序的,因此值將更改。 如何創建這些左側的徽章? 如果可能的話,我更喜歡使用代碼方法,而不是PNG圖片。

更新:

請您看看:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    CGRect priorityLabelRect = CGRectMake(10, 5, 20, 30);
    UILabel *priorityLabel = [[UILabel alloc] initWithFrame:priorityLabelRect];
    priorityLabel.layer.cornerRadius = 5.0f;
    priorityLabel.layer.backgroundColor = [[UIColor grayColor] CGColor];
    priorityLabel.tag = kPriorityValueTag;
    [cell.contentView addSubview:priorityLabel];
    [priorityLabel release];

    CGRect meatLabelRect = CGRectMake(80, 5, 300, 30);
    UILabel *meatLabel = [[UILabel alloc] initWithFrame:meatLabelRect];
    meatLabel.tag = kMeatValueTag;
    [cell.contentView addSubview:meatLabel];
    [meatLabel release];

    cell.showsReorderControl = YES;
}

// Configure the cell.
[self configureCell:cell atIndexPath:indexPath];

return cell;
}

但是優先級周圍沒有顯示灰色區域。
如果我添加一個新的,優先級周圍的灰色區域會出現少於一秒鍾的時間,但是會立即消失。 更不用說優先級值不在灰色區域的中心。

知道我在做什么錯嗎?

UILabel添加到單元格, UILabel將其格式化為自己喜歡的格式。 對於圓角,設置label.layer.cornerRadius

  1. 為徽章創建一個UIView。
  2. 看這里,它將說明如何繪制您想要的徽章外觀。 並繪制數字: http : //www.techotopia.com/index.php/An_iPhone_Graphics_Drawing_Tutorial_using_Quartz_2D

  3. 創建一個將接收單元格編號並將其繪制在單元格中的變量。

它應該看起來像這樣-

- (void)drawRect:(CGRect)rect {

        CGContextRef context = UIGraphicsGetCurrentContext();

        CGContextSetLineWidth(context, 2.0);
        CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
        CGRect rectangle = CGRectMake(10,10,40,40);
        CGContextAddRect(context, rectangle);
        CGContextStrokePath(context);
        CGContextSetFillColorWithColor(context, [UIColor grayColor].CGColor);
        CGContextFillRect(context, rectangle);
        CGPoint point =CGPointMake(20,20);
        [self.cellNumber drawAtPoint:point withFont:font];

}

4將BadgeView添加到您的單元格中,然后在CellForRawAtIndexPath中將數字傳遞到徽章視圖。

祝好運

您可以進行組合控制。 這是一個UIImageView,具有一個UIImage和一個UILabel作為子視圖。

一個常規對象,它的UIImageView.image帶有灰色矩形,然后是帶有白色數字的UILabel。 然后只需更改標簽文本的值即可。

如果從UIImageView開始並為其子類化,則可以將其直接粘貼到常規UITableViewCells中,因為它們已經具有用於UIImageView的空間。

暫無
暫無

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

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