Search code examples
iosobjective-csignal-strength

How to display BLE RSSI as signal strength bars iPhone


I am writing an app that shows a list of BLE devices.

I'd like to show the signal strength graphically of each device like cellular signal bars instead of the actual number.

Does anyone know how to do this?


Solution

  • You may use an UIImageView to render only a part of your image. Let's break it down:

    1. Have an image showing full bars;
    2. Place a UIImageView to show your image on the screen;
    3. Create a CGRect to slice a portion your image and set it on your_image_view.layer.contentsRect - Note that 1.0 = 100%;
    4. Control which parts of the image will be show using that CGRect;

    Example:

    UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    CGRect frame = CGRectMake(/* x */ 0, /* y */ 0.5, /* width */ 1, /* height */ 0.25);
    view.layer.contentsRect = frame;
    view.image = [UIImage imageNamed:@"ble_bars.png"];
    

    Reading the documentation about CGMakeRect and contentsRect should help you.