ArcGIS Runtime SDK for iOS(三) --- Callout的自定义属性展示

2016.4.15 武汉 小雨
by SevenJohs.

  • 概述:

        在上个博文的基础上,添加Callout的自定义属性展示。
    
  • 内容:

    • Callout展示的两种方式
    • Steps:

      • 新建自定义的继承UIView的View,做为Callout展示;
      • 展示。
  • Callout展示的两种方式

    1. 直接show
    
[_mapView.callout showCalloutAtPoint:locationPnt forGraphic:targetGraphic animated:YES];
2.实现infoTemplate的协议方法
//实现前设置代理为自身
#pragma mark AGSInfoTemplateDelegate Delegate method
-(NSString *)detailForGraphic:(AGSGraphic *)graphic screenPoint:(CGPoint)screen mapPoint:(AGSPoint *)mapPoint{

}

-(NSString *)titleForGraphic:(AGSGraphic *)graphic screenPoint:(CGPoint)screen mapPoint:(AGSPoint *)mapPoint{

}
//注意:协议方法存在优先级,下列方法,较以上两个方法有较高的优先级
-(UIView *)customViewForGraphic:(AGSGraphic *)graphic screenPoint:(CGPoint)screen mapPoint:(AGSPoint *)mapPoint{

}
  • 新建自定义的继承UIView的View,做为Callout展示
//  MyCalloutView.h
//  Created by SevenJohs on 16/4/15.
//
//
#import <UIKit/UIKit.h>

@interface MyCalloutView : UIView
@property(nonatomic,strong) UILabel* titleLabel;
@property(nonatomic,strong) UITableView* tableView;
@property(nonatomic,strong) NSDictionary* attributes;
@end
//  MyCalloutView.m
//  Created by SevenJohs on 16/4/15.
//

#import "MyCalloutView.h"
//设置table数据源与代理
@interface MyCalloutView()<UITableViewDelegate,UITableViewDataSource>
@end

@implementation MyCalloutView
//初始化frame
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self) {
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, 21)];
        [self addSubview:_titleLabel];
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 21, frame.size.width, frame.size.height-21)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self addSubview:_tableView];
    }
    return self;
}

#pragma  mark -- UITableviewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.attributes ? self.attributes.allKeys.count:0;
}

-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString* identifier = @"cell";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier];

    NSString* key = [[self.attributes.allKeys objectAtIndex:indexPath.row] description];
    NSString* value = [[self.attributes objectForKey:key] description];

    if(cell) {
        cell.textLabel.text = key;
        cell.detailTextLabel.text = value;
    } else {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
        cell.textLabel.text = key;
        cell.detailTextLabel.text = value;
    }
    return cell;
}

@end

在主控制器中进行连接(实现协议方法):

-(UIView *)customViewForGraphic:(AGSGraphic *)graphic screenPoint:(CGPoint)screen mapPoint:(AGSPoint *)mapPoint{

    MyCalloutView* myCalloutView = [[MyCalloutView alloc]initWithFrame:CGRectMake(0, 0, 200, 150)];
    myCalloutView.backgroundColor = [UIColor colorWithRed:0x3a/255.0 green:0x96/255.0 blue:0xeb/255.0 alpha:0.6];

    NSString *type = @"";
    if([graphic attributeForKey:@"type"]){
        type = [[graphic attributeForKey:@"type"] description];
    }

    if([type isEqualToString:@"2"]){
        UIView* v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
        v.backgroundColor = [UIColor redColor];

        return v;
    }

    myCalloutView.titleLabel.text = type;
    myCalloutView.attributes = graphic.allAttributes;

    return myCalloutView;
}
  • 添加Graphic
[_mapView.callout showCalloutAtPoint:locationPnt forGraphic:targetGraphic animated:YES];

END

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值