again another question:
I have a scrollView where the images loaded by createView, but how can i add an image from an url? In my case if i change ../images/.... to http://www.codeworxx.com/images/... the images are not loading. In coverFlowView it works?!?!
Any ideas? Here's my code:
var image1 = Ti.UI.createView({width:320,height:156,backgroundImage:'../images/gallery/bmw3er/image1.jpg'});
var image2 = Ti.UI.createView({width:320,height:156,backgroundImage:'../images/gallery/bmw3er/image2.jpg'});
var image3 = Ti.UI.createView({width:320,height:156,backgroundImage:'../images/image3.jpg'});
var image4 = Ti.UI.createView({width:320,height:156,backgroundImage:'../images/image4.jpg'});
var image5 = Ti.UI.createView({width:320,height:156,backgroundImage:'../images/image5.jpg'});
var image6 = Ti.UI.createView({width:320,height:156,backgroundImage:'../images/image6.jpg'});
var scrollView = Ti.UI.createScrollableView({
views:[image1,image2,image3,image4,image5,image6],
showPagingControl:true,
clipViews:false,
top:0,
left:30,
right:30,
width:320,
height:156,
opacity:0
});
Thanks again for your help.
Sascha
Why don't you add Titanium.UI.ImageView to the scrollview.
There is a good example here of scrolling images.
http://shakilspace.blogspot.com/2011/02/appcelerator-titanium-scrollview-swipe.html
There is also a Titanium scrolling image example app available on Codecanyon
http://codecanyon.net/item/swipeable-photo-gallery/145864
Related
What way is more convenient to set image from my app assets in my app Image View? I have two ways: the first one is function UIImage(named: String) or UIImage and both is working for me, but I want to know which one is the best ,so I can use one in the future
here is two examples
// first
let myImages1 = ["dice1", "dice2", "dice3", "dice4", "dice5", "dice6"]
#IBOutlet weak var diceImageView1: UIImageView!
diceImageView1.image = UIImage(named: myImages1[index1])
// second
let myImages2 = [ image1, image2, image3, image4, image5, image6 ]
#IBOutlet weak var diceImageView2: UIImageView!
diceImageView2.image = myImages2[index2]
We're using Images from assets catalog instead String names. It's the better way to set UIImage. But from swift 4.2 we can't use asset names anymore.
We should use image literal.
Here's the example:
let logoImageView: UIImageView = {
let iv = UIImageView()
// Set image with image literal
iv.image = #imageLiteral(resourceName: "feedback")
return iv
}()
Look at the screenshot below.
After you've typed Image Literal you can double click on that and choose your image from assets catalog. Here is the screenshot.
But last time I use this lib R.swift. Get strong typed, autocompleted resources like images, fonts and segues in Swift projects.
How it looks in code:
You can create an extension for UIImage and have static variables holding your images.
extension UIImage {
static var dice1: UIImage? {
return UIImage(named: "dice1")
}
}
let imageView = UIImageView()
imageView.image = UIImage.dice1
Or you can use image literals in Xcode which are nice because you can see the actual image
I have a slider that fades images.
The transition works, the new image fades it, but the previous image doesn't fade out.
The previous image simply disappears after the next image has fully faded in.
For opaque images this of course is perfectly fine as we don't need to the previous image fade out. It's simply overlaid by the new image.
The problem is that my images have transparent regions, so it would be necessary that the previous image fades out.
How could I achieve this?
My current code is this:
jssor_1_slider_init = function() {
var jssor_1_SlideshowTransitions = [
{$Duration:800,$Opacity:2}
];
var jssor_1_options = {
$AutoPlay: 1,
$LazyLoading: 1,
$SlideshowOptions: {
$Class: $JssorSlideshowRunner$,
$Transitions: jssor_1_SlideshowTransitions
}
};
var jssor_1_slider = new $JssorSlider$("jssor_1", jssor_1_options);
/*#region responsive code begin*/
var MAX_WIDTH = 256;
function ScaleSlider() {
var containerElement = jssor_1_slider.$Elmt.parentNode;
var containerWidth = containerElement.clientWidth;
if (containerWidth) {
var expectedWidth = Math.min(MAX_WIDTH || containerWidth, containerWidth);
jssor_1_slider.$ScaleWidth(expectedWidth);
}
else {
window.setTimeout(ScaleSlider, 30);
}
}
Given image with transparent area, to make jssor slider with slideshow, you can use twins transitions.
Open options window, choose one or more twins slideshow transitions.
Followed by documentation and examples on this page
I think you need this {$Duration:700,$Opacity:2,$Brother:{$Duration:700,$Opacity:2}}
Example : Fade Twins
I wan´t to take a screenshot of a NSView but when I do this, I get an image without the background. All the subviews are show, but not the background. I use this code:
if let image = NSImage(data: background.dataWithPDF(inside: background.bounds)) {
let imageView = NSImageView(image: image)
imageView.imageScaling = .scaleProportionallyUpOrDown
return NSImageView(image: image)
}
I thought, ok when I get only the subviews, then I will make a screenshot of the superview and I thried the following:
if let superview = background.superview, let image = NSImage(data: superview.dataWithPDF(inside: background.frame)) {
let imageView = NSImageView(image: image)
imageView.imageScaling = .scaleProportionallyUpOrDown
return NSImageView(image: image)
}
But I get the same result. Even if I set the background color of my background view I don´t get an image without transparent background.
How can I resolve this?
thank you
Artur
I got an Answer:
background.lockFocus()
if let rep = NSBitmapImageRep(focusedViewRect: background.bounds){
let img = NSImage(size: background.bounds.size)
img.addRepresentation(rep)
return NSImageView(image: img)
}
background.unlockFocus()
You could have converted the views backing layer.backgroundColor to an image. Then assign the image to a backing image view that sits in the 0th index of your views heirarchy and use the method dataWithPDF -> that will successfully capture a background.
I have an image with a dimension of about 200x2000 pixels. I want to display the image centered in a 200x200 rectangle but I want to be able to move it up and down. Best I can figure I need to add an NSImageView to an NSScrollView but I can't figure out how or even if this is the best way. This is my first day of OS X development...
After some googling I found this from which I was able to come up with this
class MasterViewController: NSViewController {
var Photo: NSImageView!
#IBOutlet var scroll: NSScrollView!
override func viewDidLoad() {
super.viewDidLoad()
var imageRect: NSRect
self.Photo = NSImageView.init()
self.Photo.image = NSImage.init(named:"horizon")
imageRect = NSMakeRect(0.0, 0.0, self.Photo.image!.size.width, self.Photo.image!.size.height)
print("image size", imageRect)
self.Photo = NSImageView(frame: imageRect)
self.Photo.setBoundsSize(NSSize(width: imageRect.width, height: imageRect.height))
self.Photo.imageScaling = NSImageScaling.ScaleNone
self.scroll.setFrameSize(NSSize(width: imageRect.width,height: imageRect.width))
self.scroll.hasVerticalScroller = true
self.scroll.hasHorizontalScroller = true
self.Photo.setFrameSize(CGSize(width: imageRect.width,height: imageRect.width))
self.scroll.documentView = self.Photo
//print(self.scroll.documentView?.frame)
//self.scroll.setC contentSize = NSSize(width: 200, height: 2000)
//self.Photo.image = NSImage.init(named:"bezel")
//self.scroll.addSubview(self.Photo)
}
but I can't get the image to show up inside the scrollview
#lusher00: in your example, you initialize twice self.Photo, first with an init() and then with (frame: imageRect), this probably explains why image don't show up.
You could set the imageView as the documentView of the NSScrollView, as below:
#IBOutlet var scrollView: NSScrollView!
var imageRect: NSRect
// Initialize below the imageView image with appropriate content (to adapt)
imageView.image = NSImage.init(named:"horizon")
imageRect = NSMakeRect(0.0, 0.0, imageView.image!.size.width, imageView.image!.size.height)
imageView.setFrameSize(CGSize(width: imageRect.width, height: imageRect.height))
imageView.imageScaling = NSImageScaling.ScaleNone
scrollView.documentView = imageView
scrollView.hasVerticalScroller = true
scrollView.hasHorizontalScroller = true
Just add the image view as a subview of the scrollview.
scrollView.addSubview(imageView)
You can set the position of the imageview, which will position it inside the scrollview.
The scrollview needs to know how large its content size is to enable scrolling of that area. So dont forget to update the contentSize property of the scrollview.
E.g. adding the imageView of 200x200 to the scrollView with a frame of 200x200. Setting the contentSize to 400x400 and calling imageView.center = scrollView.center, will center the image and allow some scrolling around the image, within the 200x200 visible frame of the scrollview.
You can also get the current offset of the scrollView by checking contentOffset.
If you need to track as the user scrolls, you can use scrollViewDidScroll. Check the docs for the scrollview for some other options.
i'm a new developer for ios. Is there a way where i could add a UIImageView on top of a UILabel ? I tried this but image is hidden from UILabel :(
var imageTick:UIImage = UIImage(named: "Trash-icon.png")
var imageView:UIImageView = UIImageView(frame: CGRectMake(self.bounds.size.width-50, self.bounds.size.height/2, 30, 30))
imageView.image = imageTick
labelTick.addSubview(imageView)
self.addSubview(labelTick)
These objects are stacked in the order in which they are added to their superview.
Instead of adding the labelTick subview to the imageView you want to add it to the super view before the image imageView:
var imageTick:UIImage = UIImage(named: "Trash-icon.png")
var imageView:UIImageView = UIImageView(frame: CGRectMake(self.bounds.size.width-50, self.bounds.size.height/2, 30, 30))
imageView.image = imageTick
self.addSubview(labelTick)
self.addSubview(imageView)
Alternatively you can also use insertSubview, to insert them above or below another one in the superview:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instm/UIView/insertSubview:aboveSubview: