Tuesday, July 5, 2016

Custom shaped buttons in iOS

We had to implement a remote control-like UI in our app, and there were these 4-5 buttons which formed a circle, and the user can tap anywhere on the button to use the function. So we needed an odd shaped button. 




I found the library named OBShapedButton created by Ole Begemann and decided to give it a try. It just works perfect! The code is available in gitHub, so this post is just a testament that the OBShapedButton library works just as promised, and it's very easy to integrate in to projects! 


Link to the library:


https://github.com/ole/OBShapedButton

Thanks, & Cheers, Mr OB!!

Sunday, July 3, 2016

iOS UITableView keep the separator line visible when the cell is selected

Usually when we select the first cell in a tableView on iOS, the separator line between the first row and second row disappears. This is annoying, and usually the UI design recommends the separator line to be there always. The following code fixes the issue. It adds a view as the separator line between cells. 

Remember we have to keep the UITableView's selection style as UITableViewCellSeparatorStyleNone and separator style as UITableViewCellSelectionStyleNone



- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
    UIView *selectionBgView = [[UIView alloc] init];
    selectionBgView.backgroundColor = [UIColor colorWithRed:245.0/255.0f green:242.0f/255.0f blue:241.0/255.0f alpha:1.0];
    cell.selectedBackgroundView = selectionBgView;

    UIView* separatorLine = [[UIView alloc] initWithFrame:CGRectMake(0, BOX_TABLE_ROW_HEIGHT-1, boxesTableView.width, 1)];
    separatorLine.backgroundColor = COLOR_GRAY_212;
    [cell.selectedBackgroundView addSubview:separatorLine];
    return YES;

}