//
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let one = VCTwo()
let oneNav = UINavigationController(rootViewController: one)
oneNav.tabBarItem = UITabBarItem(title: "收到", image: UIImage (named: "22"), selectedImage: UIImage (named: "22"))
let two = TwoViewController()
let twoNav = UINavigationController(rootViewController: two)
twoNav.tabBarItem = UITabBarItem(title: "但是", image: UIImage (named: "33"), selectedImage: UIImage (named: "33"))
let three = ThreeViewController()
let threeNav = UINavigationController(rootViewController: three)
threeNav.tabBarItem = UITabBarItem(title: "国服", image: UIImage (named: "222"), selectedImage: UIImage (named: "222"))
let tbv = UITabBarController()
tbv.viewControllers = [oneNav,twoNav,threeNav]
self.window!.rootViewController = tbv
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
import UIKit
class ViewController: UIViewController {
let mArr:NSMutableArray = []
override func viewDidLoad() {
super.viewDidLoad()
//json文件k路径
let path = Bundle.main.path(forResource: "daren", ofType: "json")
//将json转换成URL
let url = URL(fileURLWithPath: path!)
//将url转换成data数据
do {
let data = try Data(contentsOf: url)
//把数据抓换成json
let jsonData = try JSONSerialization.jsonObject(with: data, options:JSONSerialization.ReadingOptions.mutableContainers)
let arr:NSArray = jsonData as! NSArray
print(arr)
for item in arr {
let k:NSDictionary = item as! NSDictionary
if k.object(forKey: "type")as!String == "0"{
let md:OneMD = OneMD(headImage: k.object(forKey: "headImage") as! String, title: k.object(forKey: "titlt") as! String, time: k.object(forKey: "time") as! String, detailTitle: k.object(forKey: "detailTitle") as! String, img: k.object(forKey: "img") as! String, num: k.object(forKey: "num") as! String, type: k.object(forKey: "type") as! String)
mArr.add(md)
}else if k.object(forKey: "type")as!String == "1"{
let md:TwoMD = TwoMD(headImage: k.object(forKey: "headImage") as! String, title: k.object(forKey: "titlt") as! String, time: k.object(forKey: "time") as! String, detailTitle: k.object(forKey: "detailTitle") as! String, img: k.object(forKey: "img") as! NSArray, num: k.object(forKey: "num") as! String, type: k.object(forKey: "type") as! String)
mArr.add(md)
}else{
let md:ThreeMD = ThreeMD(headImage: k.object(forKey: "headImage") as! String, title: k.object(forKey: "titlt") as! String, time: k.object(forKey: "time") as! String, detailTitle: k.object(forKey: "detailTitle") as! String, img: k.object(forKey: "img") as! String, num: k.object(forKey: "num") as! String, type: k.object(forKey: "type") as! String)
mArr.add(md)
}
}
} catch let error as Error? {
}
}
}
Two one y
import UIKit
class TwoViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//右侧按钮
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "哈哈", style: UIBarButtonItem.Style.plain, target: self, action: nil)
self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage (named: "1"), style: UIBarButtonItem.Style.plain, target: self, action: nil)
// self.view.backgroundColor = UIColor .black
self.navigationController?.navigationBar.barTintColor = UIColor .white
let items=["电话","短信"] as [AnyObject]
let segmented=UISegmentedControl(items:items)
segmented.center=self.view.center
segmented.selectedSegmentIndex=0 //默认选中第1项
segmented.addTarget(self, action: #selector(segmentDidchange),
for: UIControl.Event.valueChanged) //添加值改变监听
self.navigationItem.titleView = segmented
// Do any additional setup after loading the view.
}
@objc func segmentDidchange(segmented:UISegmentedControl){
//获得选项的索引
print(segmented.selectedSegmentIndex)
//获得选择的文字
print(segmented.titleForSegment(at: segmented.selectedSegmentIndex))
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
import UIKit
class one: UIViewController,UITableViewDelegate,UITableViewDataSource {
var tabv = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.barTintColor = UIColor .white
self.view.backgroundColor = UIColor .white
tabv = UITableView(frame: self.view.frame, style: UITableView.Style.grouped)
tabv.delegate = self
tabv.dataSource = self
self.view.addSubview(tabv)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return 2
}else if section == 1{
return 3
}else{
return 4
}
}
func numberOfSections(in tableView: UITableView) -> Int {
return 3
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellID = "cell"
var cell = tableView.dequeueReusableCell(withIdentifier: cellID)
if cell == nil{
cell = UITableViewCell.init(style: UITableViewCell.CellStyle.value1, reuseIdentifier: cellID)
}
if indexPath.section == 0{
if indexPath.row == 0{
tabv.rowHeight = 400
// 分组一 第一行
let img1 = UIImageView(frame: CGRect(x: 10, y: 10, width: 70, height: 70))
img1.image = UIImage (named: "2")
cell?.addSubview(img1)
let lab1 = UILabel(frame: CGRect(x: 90, y: 10, width: 300, height: 30))
lab1.text = "飒飒大撒撒"
lab1.numberOfLines = 0
cell?.addSubview(lab1)
let lab2 = UILabel(frame: CGRect(x: 90, y: 40, width: 300, height: 30))
lab2.text = "九点"
lab2.textColor = UIColor .lightGray
lab2.numberOfLines = 0
cell?.addSubview(lab2)
let img2 = UIImageView(frame: CGRect(x: 10, y: 100, width: 400, height: 250))
img2.image = UIImage (named: "3")
cell?.addSubview(img2)
let btn = UIButton(frame: CGRect(x: 10, y: 360, width: 50, height: 20))
btn.setTitle("点击", for: UIControl.State.normal)
btn.setTitleColor(UIColor .black, for: UIControl.State.normal)
btn.backgroundColor = UIColor .orange;
cell?.addSubview(btn)
let btn1 = UIButton(frame: CGRect(x: 260, y: 360, width: 50, height: 20))
btn1.setTitle("点击", for: UIControl.State.normal)
btn1.setTitleColor(UIColor .black, for: UIControl.State.normal)
btn1.backgroundColor = UIColor .orange;
cell?.addSubview(btn1)
let btn2 = UIButton(frame: CGRect(x: 350, y: 360, width: 50, height: 20))
btn2.setTitle("点击", for: UIControl.State.normal)
btn2.setTitleColor(UIColor .black, for: UIControl.State.normal)
btn2.backgroundColor = UIColor .orange;
cell?.addSubview(btn2)
}else{
tabv.rowHeight = 400
// 分组一 第2行
let img1 = UIImageView(frame: CGRect(x: 10, y: 10, width: 70, height: 70))
img1.image = UIImage (named: "4")
cell?.addSubview(img1)
let lab1 = UILabel(frame: CGRect(x: 90, y: 10, width: 300, height: 30))
lab1.text = "飒飒大撒撒"
lab1.numberOfLines = 0
cell?.addSubview(lab1)
let lab2 = UILabel(frame: CGRect(x: 90, y: 40, width: 300, height: 30))
lab2.text = "九点"
lab2.textColor = UIColor .lightGray
lab2.numberOfLines = 0
cell?.addSubview(lab2)
let img2 = UIImageView(frame: CGRect(x: 10, y: 100, width: 400, height: 250))
img2.image = UIImage (named: "5")
cell?.addSubview(img2)
let btn = UIButton(frame: CGRect(x: 10, y: 360, width: 50, height: 20))
btn.setTitle("点击", for: UIControl.State.normal)
btn.setTitleColor(UIColor .black, for: UIControl.State.normal)
btn.backgroundColor = UIColor .orange;
cell?.addSubview(btn)
let btn1 = UIButton(frame: CGRect(x: 260, y: 360, width: 50, height: 20))
btn1.setTitle("点击", for: UIControl.State.normal)
btn1.setTitleColor(UIColor .black, for: UIControl.State.normal)
btn1.backgroundColor = UIColor .orange;
cell?.addSubview(btn1)
let btn2 = UIButton(frame: CGRect(x: 350, y: 360, width: 50, height: 20))
btn2.setTitle("点击", for: UIControl.State.normal)
btn2.setTitleColor(UIColor .black, for: UIControl.State.normal)
btn2.backgroundColor = UIColor .orange;
cell?.addSubview(btn2)
}
}else if indexPath.section == 1{
if indexPath.row == 0{
tabv.rowHeight = 200
// 分组2 第一行
}else if indexPath.row == 1{
tabv.rowHeight = 400
// 分组2 第2行
}else{
tabv.rowHeight = 100
// 分组2 第3行
}
}else{
if indexPath.row == 0{
tabv.rowHeight = 100
// 分组3 第1·行
}else if indexPath.row == 1{
tabv.rowHeight = 50
// 分组3 第2行
}else if indexPath.row == 2{
tabv.rowHeight = 100
// 分组3 第3行
}else {
tabv.rowHeight = 30
// 分组3 第4行
}
}
return cell!
}
}
import UIKit
class OneMD: NSObject {
var headImage:String
// 主标题
var title:String
// 时间
var time:String
// 副标题
var detailTitle:String
// 图片
var img:String
// 数量
var num:String
// 类型
var type:String
init(headImage:String,title:String,time:String,detailTitle:String,img:String,num:String,type:String) {
// 赋值
self.headImage = headImage
self.title = title
self.time = time
self.detailTitle = detailTitle
self.img = img
self.num = num
self.type = type
}
}
import UIKit
class TwoMD: NSObject {
var headImage:String
// 主标题
var title:String
// 时间
var time:String
// 副标题
var detailTitle:String
// 图片
var img:NSArray
// 数量
var num:String
// 类型
var type:String
init(headImage:String,title:String,time:String,detailTitle:String,img:NSArray,num:String,type:String) {
// 赋值
self.headImage = headImage
self.title = title
self.time = time
self.detailTitle = detailTitle
self.img = img
self.num = num
self.type = type
}
}
import UIKit
class ThreeMD: NSObject {
var headImage:String
// 主标题
var title:String
// 时间
var time:String
// 副标题
var detailTitle:String
// 图片
var img:String
// 数量
var num:String
// 类型
var type:String
init(headImage:String,title:String,time:String,detailTitle:String,img:String,num:String,type:String) {
// 赋值
self.headImage = headImage
self.title = title
self.time = time
self.detailTitle = detailTitle
self.img = img
self.num = num
self.type = type
}
}