1

有没有办法将鹅卵石表盘上的 textlayer 颜色设置为多种颜色?例如,如果时间是 12:00,我希望 1 为一种颜色,2 为第二种颜色,: 为第一种颜色,依此类推。我在任何地方都找不到这些信息,而且该方法似乎只采用一个变量。

4

1 回答 1

1

这很容易做到,您每次都需要更改上下文颜色,例如:

  void time_update_callback(Layer *layer, GContext *ctx)
  {
  /* Get a layer rect to re-draw */
  GRect layer_bounds = layer_get_bounds(layer);
  /* Get time from variables */ 
  char h1[2];
  char h2[2];
  char m1[2];
  char m2[2];
  h1[0] = hour_text_visible[0];
  h2[0] = hour_text_visible[1];
  m1[0] = minute_text_visible[0];
  m2[0] = minute_text_visible[1];
  h1[1] = h2[1] = m1[1] = m2[1] = 0;
  /* Add y padding to GRect */
  layer_bounds.origin.y += 1;
  /* Aux copy */ 
  GRect origin = layer_bounds;
  /* Change color to Black */
  graphics_context_set_text_color(ctx, GColorBlack);
  /* Move */
  layer_bounds.origin.x += 4;
  layer_bounds.origin.y += 1;
  /* Draw assuming you have a font loaded */ 
  graphics_draw_text(ctx, h1, font, layer_bounds, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
  /* Move again */
  layer_bounds.origin.x += 20;
  /* Draw black also */
  graphics_draw_text(ctx, h2, font, layer_bounds, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
  /* move */
  layer_bounds.origin.x += 30;
  /* Change color to Blue */
  graphics_context_set_text_color(ctx, GColorBlue);
  /* Draw in blue */
  graphics_draw_text(ctx, m1, font, layer_bounds, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
  /* etc */
  }
于 2016-06-10T11:49:38.883 回答