I have side menu using tableview and it works well but i don't know how to add a circle profile image to the side menu in swift. Please help me how to do this.here is my code,
override function tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("CELL") as? UITableViewCell
var cell1 = tableView.dequeueReusableCellWithIdentifier("Cell1") as? UITableViewCell
if (cell == nil) {
cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "CELL")
cell!.backgroundColor = UIColor.clearColor()
cell!.textLabel?.textColor = UIColor.whiteColor()
let selectedBackgroundView = UIView(frame: CGRectMake(0, 0, cell!.frame.size.width, cell!.frame.size.height))
selectedBackgroundView.backgroundColor = UIColor.grayColor().colorWithAlphaComponent(0.2)
cell!.selectedBackgroundView = selectedBackgroundView
}
cell!.textLabel?.font = UIFont.systemFontOfSize(14)
cell!.textLabel?.text = self.items[indexPath.row];
var imageView = UIImageView(frame: CGRectMake(5, 10, 20, 20));
var image = UIImage(named:images[indexPath.row]);
imageView.image = image;
cell!.imageView?.image = imageView.image
return cell!
}
Thanks
try this
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat{
return 70 // Please change its according to you
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?{
var view = UIView(frame: CGRectMake(0, 0, tableView.bounds.size.width, 70))
view.backgroundColor = UIColor.clearColor()
var profileImageView = UIImageView(frame: CGRectMake(40, 5, 60, 60)) // Change frame size according to you ..
profileImageView.image = UIImage(named: "image name") //Image set your
view.addSubview(profileImageView)
return view
}
It will work fine .. change minor according to you
You can use
Objective c
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection (NSInteger)section
{
UIView *headerView = // the size of the header you want
UIImageView *userImageView = // the size of the UserImage you want
userImageView.layer.cornerRadius = userImageView.bounds.size.width/2;
userImageView.image = // the userImage
[headerView addSubView:userImageView];
return headerView;
}
Swift
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?{
var headerView = UIView( // size you want
var userImageView = UIImageView(frame: CGRectMake(// size you want))
userImageView.image = // user image
userImageView.layer.cornerRadius = userImageView.bounds.size.width/2'
headerView .addSubview(userImageView )
return headerView
}
Don't forget to set the height of the header accordingly
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.