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;

}

Tuesday, June 21, 2016

iOS UITableView keep one row(cell) selected


To keep one row selected in a tableview, add the below code after the table is loaded, (if its on page load, a good place would be to keep the below code in viewDidAppear. It worked well for me!)


UITableViewCell *selectedCell = [myTableView cellForRowAtIndexPath:selectedIndexPath];
if (selectedCell) {
    selectedCell.selected = YES;
}

[self tableView:myTableView didSelectRowAtIndexPath:selectedIndexPath];

[myTableView selectRowAtIndexPath:selectedIndexPath animated:YES scrollPosition:UITableViewScrollPositionNone];

Sunday, April 3, 2016

Displaying animated images/Gif in UIImageView


The easiest way to show animated image/gif on a UIImageView in iOS would be to give it the collection of images to animate, and call startAnimation

UIImageView* imgView = [[UIImageView alloc] init]; 
imgView.animationImages = [NSArray arrayWithObjects: 
[UIImage imageNamed:@"imgAtPosition1.gif"], 
[UIImage imageNamed:@"imgAtPosition2.gif"], 
[UIImage imageNamed:@"imgAtPosition3.gif"], 
[UIImage imageNamed:@"imgAtPosition4.gif"], 
.
.
., nil]; 
imgView.animationDuration = 0.4f; 
imgView.animationRepeatCount = 100; 
[imgView startAnimating]; 
[self.view addSubview: imgView];



Thursday, February 25, 2016

Graphics card issue on Macbook Pro 2011

This is a known issue in Macbook Pros around 2011. They have two graphics cards, which are switched dynamically for the best performance/output. If your Macbook starts showing screens with lines all over, and gets stuck and you've to restart frequently, this could be a Graphics card issue. Easy fix would be to install the app called gfxCardStatus, which allows you to select how the graphics cards are being used. It's fixed the issue for many people in our company.