Posts

Create Line with arrow in iOS Objective C

Solution: In iOS you can create a Line using CGContextref.The below code is used for draw a line in a view in x1,y1, is 0,0 and x2,y2 is 20,20. Also add the cap in the end of the line to show the line as arrow      CGContextRef  ctx =  UIGraphicsGetCurrentContext ();      CGRect  rect =  CGRectMake ( 0 ,  0,20,20 )      CGContextClearRect (ctx, rect);     CGContextSetStrokeColorWithColor(ctx, color.CGColor);     CGContextSetLineCap(ctx, kCGLineCapRound);     CGContextSetLineWidth(ctx, 10);     CGContextSetAlpha(ctx, 1);     CGContextMoveToPoint(ctx, 0, 0); //add the cap              CGPoint fPoint=CGPointMake(0,0);         CGPoint ePoint=CGPointMake(20,20);         CGFloat capHeight = 1 * 4.0f;         CGFloat angle = [self angleWithF...

Create Line in iOS Objective C

Solution: In iOS you can create a Line using CGContextref.The below code is used for draw a line in a view in x1,y1, is 0,0 and x2,y2 is 20,20.     CGContextRef  ctx =  UIGraphicsGetCurrentContext ();    CGRect  rect =  CGRectMake ( 0 ,  0,20,20 );    CGContextClearRect (ctx, rect);   CGContextSetStrokeColorWithColor(ctx, color.CGColor);    CGContextSetLineCap(ctx, kCGLineCapRound);    CGContextSetLineWidth(ctx, 10);    CGContextSetAlpha(ctx, 1);    CGContextMoveToPoint(ctx, 0, 0);    CGContextAddLineToPoint(ctx, 20, 20);    CGContextStrokePath(ctx);     CGContextDrawPath (ctx,  kCGPathFillStroke );

Create circle in iOS Objective C with and without fill

Solution: In iOS you can create a circle using CGContextref. The below code is used for draw a circle in a view with 0 x axis,0 y axis,width 20 and height 20..      CGContextRef  ctx =  UIGraphicsGetCurrentContext ();      CGRect  rect =  CGRectMake ( 0 ,  0,20,20 )      CGContextClearRect (ctx, rect);      CGContextSetLineWidth (ctx, 10 );      CGContextStrokeEllipseInRect(UIGraphicsGetCurrentContext(), rect); If you want to fill the rectangle then add the below code          CGContextSetFillColorWithColor(ctx, color.CGColor);         CGContextFillEllipseInRect(UIGraphicsGetCurrentContext(), rect);

Create rectangle in iOS Objective C with and without fill

Solution: In iOS you can create a rectangle using CGContextref.The below code is used for draw a rectangle in a view with 0 x axis,0 y axis,width 20 and height 20..     CGContextRef ctx = UIGraphicsGetCurrentContext ();     CGRect  rect = CGRectMake ( 0 , 0,20,20 )     CGContextClearRect (ctx, rect);     CGContextSetLineWidth (ctx, self . layerWidth );      CGPathRef path = CGPathCreateWithRect ( self . bounds , NULL );     CGContextAddPath (ctx, path);     CGContextDrawPath (ctx, kCGPathFillStroke ); If you want to fill the rectangle then add the below code          CGContextSetStrokeColorWithColor (ctx, color. CGColor );

Create UITableViewCell in two types iOS swift

Solution: 1) In iOS you can create tableViewCell inside your tableView and assign a class. Then in cellforRow you can use the cell using reusableIdentifier. 2) You can also create a cell in xib and insert a cell inside that and assign a class to that cell.Then in your ViewController Viewdidload method register that cell using the xib and cell identifier.Like below         self . tableView . register ( UINib (nibName: "Xibname" , bundle: nil ), forCellReuseIdentifier: "tableCell" ) After that same as reuse the cell in the cellforRow delegate method.

Set the Gradient color in iOS swift

Solution: The below code is used to set the gradient color to the particular view first declare the colors     let topColorsList: [ String ] = [ "#f12711" ]      let bottomColorsList: [ String ] = [ "#f5af19" ]         let gradientLayer: CAGradientLayer = CAGradientLayer()         gradientLayer.frame.size = cell.moreView.frame.size                  gradientLayer.colors = [hexStringToUIColor(hex: topColorsList[indexPath.row]).cgColor,hexStringToUIColor(hex: bottomColorsList[indexPath.row]).cgColor]         //Use diffrent colors         cell.moreView.layer.addSublayer(gradientLayer) The above code needs the below function for get the color from hexstring   func hexStringToUIColor (hex: String ) -> UIColor {         var cString: String = hex. trimmingCh...

How to check the string is Nil or Not and

Solution: The function will return empty string if your variable contains nil value otherwise it will returns its value. func noNilString(string: AnyObject?) -> String { if let category = string as? String { return category } else { return "" } }